code: def get_text_contents(self):
          
          contents = self.get_contents()
          # The behavior of various decode() methods and functions
          # w.r.t. the initial BOM bytes is different for different
          # encodings and/or Python versions.  ('utf-8' does not strip
          # them, but has a 'utf-8-sig' which does; 'utf-16' seems to
          # strip them; etc.)  Just sidestep all the complication by
          # explicitly stripping the BOM before we decode().
          if contents[:len(codecs.BOM_UTF8)] == codecs.BOM_UTF8:
              return contents[len(codecs.BOM_UTF8):].decode('utf-8')
          if contents[:len(codecs.BOM_UTF16_LE)] == codecs.BOM_UTF16_LE:
              return contents[len(codecs.BOM_UTF16_LE):].decode('utf-16-le')
          if contents[:len(codecs.BOM_UTF16_BE)] == codecs.BOM_UTF16_BE:
              return contents[len(codecs.BOM_UTF16_BE):].decode('utf-16-be')
          try:
              return contents.decode('utf-8')
          except UnicodeDecodeError as e:
              try:
                  return contents.decode('latin-1')
              except UnicodeDecodeError as e:
                  return contents.decode('utf-8', error='backslashreplace')
docs: This attempts to figure out what the encoding of the text is
          based upon the BOM bytes, and then decodes the contents so that
          it's a valid python string.