new_contents: """
  
  """
  
  
  from __future__ import with_statement
  
  import re
  import os
  import locale
  import sys
  from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF32
  
  PREFERRED_ENCODING = locale.getpreferredencoding()
  
  def transcode(text, input=PREFERRED_ENCODING, output=PREFERRED_ENCODING):
      """Transcode a text string"""
      try:
          return text.decode("cp437").encode("cp1252")
      except UnicodeError:
          try:
              return text.decode("cp437").encode(output)
          except UnicodeError:
              return text
  #------------------------------------------------------------------------------
  #  Functions for encoding and decoding bytes that come from
  #  the *file system*.
  #------------------------------------------------------------------------------
  
  # The default encoding for file paths and environment variables should be set
  # to match the default encoding that the OS is using.
  def getfilesystemencoding():
      """
      Query the filesystem for the encoding used to encode filenames
      and environment variables.
      """
      encoding = sys.getfilesystemencoding()
      if encoding is None:
          # Must be Linux or Unix and nl_langinfo(CODESET) failed.
          encoding = PREFERRED_ENCODING
      return encoding
  
  FS_ENCODING = getfilesystemencoding()
  
  def to_unicode_from_fs(string):
      """
      Return a unicode version of string decoded using the file system encoding.
      """
      if not isinstance(string, basestring): # string is a QString
          string = unicode(string.toUtf8(), 'utf-8')
      else:
          if not isinstance(string, unicode):
              try:
                  unic = string.decode(FS_ENCODING)
              except (UnicodeError, TypeError):
                  pass
              else:
                  return unic
      return string
      
  def to_fs_from_unicode(unic):
      """
      Return a byte string version of unic encoded using the file 
      system encoding.
      """
      if isinstance(unic, unicode):
          try:
              string = unic.encode(FS_ENCODING)
          except (UnicodeError, TypeError):
              pass
          else:
              return string
      return unic
subject: add the encoding functions