code: def Decode(data, encoding=None):
      """Returns string with non-ascii characters decoded to UNICODE.
  
      UTF-8, the suggested encoding, and the usual suspects will be attempted in
      order.
  
      Args:
        data: A string or object that has str() and unicode() methods that may
          contain an encoding incompatible with the standard output encoding.
        encoding: The suggested encoding if known.
  
      Returns:
        A text string representing the decoded byte string.
      """
      if data is None:
          return None
  
      # First we are going to get the data object to be a text string.
      # Don't use six.string_types here because on Python 3 bytes is not considered
      # a string type and we want to include that.
      if isinstance(data, six.text_type) or isinstance(
          data, six.binary_type
      ):
          string = data
      else:
          # Some non-string type of object.
          try:
              string = six.text_type(data)
          except (TypeError, UnicodeError):
              # The string cannot be converted to unicode -- default to str() which will
              # catch objects with special __str__ methods.
              string = str(data)
  
      if isinstance(string, six.text_type):
          # Our work is done here.
          return string
  
      try:
          # Just return the string if its pure ASCII.
          return string.decode("ascii")
      except UnicodeError:
          # The string is not ASCII encoded.
          pass
  
      # Try the suggested encoding if specified.
      if encoding:
          try:
              return string.decode(encoding)
          except UnicodeError:
              # Bad suggestion.
              pass
  
      # Try UTF-8 because the other encodings could be extended ASCII. It would
      # be exceptional if a valid extended ascii encoding with extended chars
      # were also a valid UITF-8 encoding.
      try:
          return string.decode("utf8")
      except UnicodeError:
          # Not a UTF-8 encoding.
          pass
  
      # Try the filesystem encoding.
      try:
          return string.decode(sys.getfilesystemencoding())
      except UnicodeError:
          # string is not encoded for filesystem paths.
          pass
  
      # Try the system default encoding.
      try:
          return string.decode(sys.getdefaultencoding())
      except UnicodeError:
          # string is not encoded using the default encoding.
          pass
  
      # We don't know the string encoding.
      # This works around a Python str.encode() "feature" that throws
      # an ASCII *decode* exception on str strings that contain 8th bit set
      # bytes. For example, this sequence throws an exception:
      #   string = '\xdc'  # iso-8859-1 'Ü'
      #   string = string.encode('ascii', 'backslashreplace')
      # even though 'backslashreplace' is documented to handle encoding
      # errors. We work around the problem by first decoding the str string
      # from an 8-bit encoding to unicode, selecting any 8-bit encoding that
      # uses all 256 bytes (such as ISO-8559-1):
      #   string = string.decode('iso-8859-1')
      # Using this produces a sequence that works:
      #   string = '\xdc'
      #   string = string.decode('iso-8859-1')
      #   string = string.encode('ascii', 'backslashreplace')
      return string.decode("iso-8859-1")
  
file_path: python-fire/fire/console/encoding.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import unicode_literals
  import sys
  import six
label_desc: Use image node_id 2 for calling a global function with example usage: Decode(data, encoding) and returns: string, None, string, string, string, string, string, string