Mercurial > bitten > bitten-test
changeset 849:bbe3cca18bec 0.6.x
0.6dev: Merged [923] from trunk.
author | hodgestar |
---|---|
date | Wed, 13 Oct 2010 15:45:18 +0000 |
parents | 3d4f61044b42 |
children | f9eecefdf174 |
files | bitten/build/api.py |
diffstat | 1 files changed, 9 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/bitten/build/api.py +++ b/bitten/build/api.py @@ -36,15 +36,21 @@ """Encode input for call. Input must be unicode or utf-8 string.""" if not isinstance(text, unicode): text = unicode(text, 'utf-8') - return text.encode( - sys.getfilesystemencoding() or sys.stdin.encoding, 'replace') + # sys.stdin.encoding might be None (if stdin is directed from a file) + # sys.stdin.encoding might be missing (if it is a StringIO object) + encoding = sys.getfilesystemencoding() or \ + getattr(sys.stdin, 'encoding', None) or 'utf-8' + return text.encode(encoding, 'replace') def _decode(text): """Decode output from call.""" try: return text.decode('utf-8') except UnicodeDecodeError: - return text.decode(getattr(sys.stdout, 'encoding', 'utf-8'), 'replace') + # sys.stdout.encoding might be None (if stdout is directed to a file) + # sys.stdout.encoding might be missing (if it is a StringIO object) + encoding = getattr(sys.stdout, 'encoding', None) or 'utf-8' + return text.decode(encoding, 'replace') class CommandLine(object):