Improve preferred encoding detection method

pull/15/head
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.
""" """
try: def yield_preferredencoding():
pref = locale.getpreferredencoding() try:
# Mac OSX systems have this problem sometimes pref = locale.getpreferredencoding()
if pref == '': u'TEST'.encode(pref)
return 'UTF-8' except:
return pref pref = 'UTF-8'
except: while True:
sys.stderr.write('WARNING: problem obtaining preferred encoding. Falling back to UTF-8.\n') yield pref
return 'UTF-8' return yield_preferredencoding().next()
class DownloadError(Exception): class DownloadError(Exception):
"""Download Error exception. """Download Error exception.

Loading…
Cancel
Save