[pypy-svn] buildbot default: don't crash if the stdout returned by hg is invalid utf-8
antocuni
commits-noreply at bitbucket.org
Mon Dec 20 10:36:08 CET 2010
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r392:a6e22df8c20f
Date: 2010-12-19 15:01 +0100
http://bitbucket.org/pypy/buildbot/changeset/a6e22df8c20f/
Log: don't crash if the stdout returned by hg is invalid 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,7 +45,10 @@
print >> sys.stderr, 'error: hg', ' '.join(argv)
print >> sys.stderr, stderr
raise Exception('error when executing hg')
- return stdout.decode('utf-8')
+ try:
+ return stdout.decode('utf-8')
+ except UnicodeDecodeError:
+ return stdout
def send(self, from_, to, subject, body):
import smtplib
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
@@ -11,12 +11,22 @@
self.mails.append((from_, to, subject, body))
-def test_non_ascii_encoding():
+def test_non_ascii_encoding_guess_utf8():
class MyHandler(BaseHandler):
def _hgexe(self, argv):
return u'späm'.encode('utf-8'), '', 0
#
handler = MyHandler()
stdout = handler.hg('foobar')
+ assert type(stdout) is unicode
assert stdout == u'späm'
+def test_non_ascii_encoding_invalid_utf8():
+ class MyHandler(BaseHandler):
+ def _hgexe(self, argv):
+ return '\xe4aa', '', 0 # invalid utf-8 string
+ #
+ handler = MyHandler()
+ stdout = handler.hg('foobar')
+ assert type(stdout) is str # if utf-8 does not work, give up
+ assert stdout == '\xe4aa'
More information about the Pypy-commit
mailing list