def fix_default_encoding():
 if (sys.getdefaultencoding() == 'utf-8'):
  return False
 sys_modules = sys.modules
 our_sys = sys_modules.pop('sys')
 try:
  vanilla_sys = __import__('sys')
  vanilla_sys.setdefaultencoding('utf-8')
  assert (sys.getdefaultencoding() == 'utf-8')
 finally:
  sys_modules['sys'] = our_sys
 for attr in dir(locale):
  if (attr[0:3] != 'LC_'):
   continue
  aref = getattr(locale, attr)
  try:
   locale.setlocale(aref, '')
  except locale.Error:
   continue
  try:
   lang = locale.getlocale(aref)[0]
  except (TypeError, ValueError):
   continue
  if lang:
   try:
    locale.setlocale(aref, (lang, 'UTF-8'))
   except locale.Error:
    os.environ[attr] = (lang + '.UTF-8')
 try:
  locale.setlocale(locale.LC_ALL, '')
 except locale.Error:
  pass
 return True

def fix_default_encoding ( ) : if ( sys . getdefaultencoding ( ) == 'utf-8' ) : return False sys_modules = sys . modules our_sys = sys_modules . pop ( 'sys' ) try : vanilla_sys = __import__ ( 'sys' ) vanilla_sys . setdefaultencoding ( 'utf-8' ) assert ( sys . getdefaultencoding ( ) == 'utf-8' ) finally : sys_modules [ 'sys' ] = our_sys for attr in dir ( locale ) : if ( attr [ 0 : 3 ] != 'LC_' ) : continue aref = getattr ( locale , attr ) try : locale . setlocale ( aref , '' ) except locale . Error : continue try : lang = locale . getlocale ( aref ) [ 0 ] except ( TypeError , ValueError ) : continue if lang : try : locale . setlocale ( aref , ( lang , 'UTF-8' ) ) except locale . Error : os . environ [ attr ] = ( lang + '.UTF-8' ) try : locale . setlocale ( locale . LC_ALL , '' ) except locale . Error : pass return True
forces utf8 solidly on all platforms .