Skip to content

Commit

Permalink
Merged in philip_thiem/setuptools (pull request #26)
Browse files Browse the repository at this point in the history
SVN Encoding Issues
  • Loading branch information
jaraco committed Nov 23, 2013
2 parents 63f856f + cc90c50 commit e9926a4
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion setuptools/svn_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import xml.dom.pulldom
import shlex
import locale
import codecs
import unicodedata
import warnings
from setuptools.compat import unicode, bytes
Expand Down Expand Up @@ -72,6 +73,34 @@ def joinpath(prefix, *suffix):
return os.path.join(*suffix)
return os.path.join(prefix, *suffix)

def determine_console_encoding():
try:
#try for the preferred encoding
encoding = locale.getpreferredencoding()

#see if the locale.getdefaultlocale returns null
#some versions of python\platforms return US-ASCII
#when it cannot determine an encoding
if not encoding or encoding == "US-ASCII":
encoding = locale.getdefaultlocale()[1]

if encoding:
codecs.lookup(encoding) # make sure a lookup error is not made

except (locale.Error, LookupError):
encoding = None

is_osx = sys.platform == "darwin"
if not encoding:
return ["US-ASCII", "utf-8"][is_osx]
elif encoding.startswith("mac-") and is_osx:
#certain versions of python would return mac-roman as default
#OSX as a left over of earlier mac versions.
return "utf-8"
else:
return encoding

_console_encoding = determine_console_encoding()

def decode_as_string(text, encoding=None):
"""
Expand All @@ -87,7 +116,7 @@ def decode_as_string(text, encoding=None):
#text should be a byte string

if encoding is None:
encoding = locale.getpreferredencoding()
encoding = _console_encoding

if not isinstance(text, unicode):
text = text.decode(encoding)
Expand Down

0 comments on commit e9926a4

Please sign in to comment.