Improve preferred encoding detection method

master
Ricardo Garcia 15 years ago
parent 0833f1eb83
commit f94b636c3e

@ -33,15 +33,15 @@ def preferredencoding():
Returns the best encoding scheme for the system, based on Returns the best encoding scheme for the system, based on
locale.getpreferredencoding() and some further tweaks. locale.getpreferredencoding() and some further tweaks.
""" """
def yield_preferredencoding():
try: try:
pref = locale.getpreferredencoding() pref = locale.getpreferredencoding()
# Mac OSX systems have this problem sometimes u'TEST'.encode(pref)
if pref == '':
return 'UTF-8'
return pref
except: except:
sys.stderr.write('WARNING: problem obtaining preferred encoding. Falling back to UTF-8.\n') pref = 'UTF-8'
return 'UTF-8' while True:
yield pref
return yield_preferredencoding().next()
class DownloadError(Exception): class DownloadError(Exception):
"""Download Error exception. """Download Error exception.

Loading…
Cancel
Save