[pypy-svn] buildbot default: try to use unicode everywhere, and don't crash if you cannot decode the output as utf-8
antocuni
commits-noreply at bitbucket.org
Mon Dec 20 10:36:10 CET 2010
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r393:8b529e55f497
Date: 2010-12-20 10:21 +0100
http://bitbucket.org/pypy/buildbot/changeset/8b529e55f497/
Log: try to use unicode everywhere, and don't crash if you cannot decode the output as utf-8
diff --git a/bitbucket_hook/hook.py b/bitbucket_hook/hook.py
--- a/bitbucket_hook/hook.py
+++ b/bitbucket_hook/hook.py
@@ -45,10 +45,7 @@
print >> sys.stderr, 'error: hg', ' '.join(argv)
print >> sys.stderr, stderr
raise Exception('error when executing hg')
- try:
- return stdout.decode('utf-8')
- except UnicodeDecodeError:
- return stdout
+ return unicode(stdout, encoding='utf-8', errors='replace')
def send(self, from_, to, subject, body):
import smtplib
@@ -104,9 +101,9 @@
if match:
# it's a binary patch, omit the content
out = out[:match.end()]
- out += '\n[cut]'
+ out += u'\n[cut]'
lines.append(out)
- return '\n'.join(lines)
+ return u'\n'.join(lines)
if __name__ == '__main__':
diff --git a/bitbucket_hook/test/test_hook.py b/bitbucket_hook/test/test_hook.py
--- a/bitbucket_hook/test/test_hook.py
+++ b/bitbucket_hook/test/test_hook.py
@@ -28,5 +28,5 @@
#
handler = MyHandler()
stdout = handler.hg('foobar')
- assert type(stdout) is str # if utf-8 does not work, give up
- assert stdout == '\xe4aa'
+ assert type(stdout) is unicode
+ assert stdout == u'\ufffdaa'
More information about the Pypy-commit
mailing list