[pypy-svn] commit/buildbot: 4 new changesets
Bitbucket
commits-noreply at bitbucket.org
Mon Dec 20 10:36:04 CET 2010
4 new changesets in buildbot:
http://bitbucket.org/pypy/buildbot/changeset/a6e22df8c20f/
changeset: r392:a6e22df8c20f
user: antocuni
date: 2010-12-19 15:01:14
summary: don't crash if the stdout returned by hg is invalid utf-8
affected #: 2 files (453 bytes)
--- a/bitbucket_hook/hook.py Sun Dec 19 14:45:44 2010 +0100
+++ b/bitbucket_hook/hook.py Sun Dec 19 15:01:14 2010 +0100
@@ -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
--- a/bitbucket_hook/test/test_hook.py Sun Dec 19 14:45:44 2010 +0100
+++ b/bitbucket_hook/test/test_hook.py Sun Dec 19 15:01:14 2010 +0100
@@ -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'
http://bitbucket.org/pypy/buildbot/changeset/8b529e55f497/
changeset: r393:8b529e55f497
user: antocuni
date: 2010-12-20 10:21:34
summary: try to use unicode everywhere, and don't crash if you cannot decode the output as utf-8
affected #: 2 files (74 bytes)
--- a/bitbucket_hook/hook.py Sun Dec 19 15:01:14 2010 +0100
+++ b/bitbucket_hook/hook.py Mon Dec 20 10:21:34 2010 +0100
@@ -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__':
--- a/bitbucket_hook/test/test_hook.py Sun Dec 19 15:01:14 2010 +0100
+++ b/bitbucket_hook/test/test_hook.py Mon Dec 20 10:21:34 2010 +0100
@@ -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'
http://bitbucket.org/pypy/buildbot/changeset/0c01f7cf0c44/
changeset: r394:0c01f7cf0c44
user: antocuni
date: 2010-12-20 10:35:59
summary: print the payload in case of error, so we can reproduce it easily
affected #: 1 file (508 bytes)
--- a/bitbucket_hook/main.py Mon Dec 20 10:21:34 2010 +0100
+++ b/bitbucket_hook/main.py Mon Dec 20 10:35:59 2010 +0100
@@ -11,6 +11,9 @@
import BaseHTTPServer
import json
import cgi
+import traceback
+import pprint
+import sys
from hook import BitbucketHookHandler
@@ -22,9 +25,17 @@
def do_GET(self):
"""Respond to a GET request."""
self.send_response(200)
- self.send_header("Content-type", "text/plain")
+ self.send_header("Content-type", "text/html")
self.end_headers()
- self.wfile.write("This is the pypy bitbucket hook.")
+ self.wfile.write("""
+ <html>
+ <p>This is the pypy bitbucket hook. Use the following form only for testing</p>
+ <form method=post>
+ payload: <input name=payload><br>
+ submit: <input type=submit>
+ </form>
+ </html>
+ """)
def do_POST(self):
length = int(self.headers['Content-Length'])
@@ -32,8 +43,13 @@
data = dict(cgi.parse_qsl(query_string))
payload = json.loads(data['payload'])
handler = BitbucketHookHandler()
- handler.handle(payload)
-
+ try:
+ handler.handle(payload)
+ except:
+ traceback.print_exc()
+ print >> sys.stderr, 'payload:'
+ pprint.pprint(payload, sys.stderr)
+ print >> sys.stderr
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
http://bitbucket.org/pypy/buildbot/changeset/9c7bc068df88/
changeset: r391:9c7bc068df88
user: antocuni
date: 2010-12-19 14:45:44
summary: partially refactor the hook to be more testable, and write a test for the fix in 12cc0caf054d
affected #: 4 files (753 bytes)
--- a/bitbucket_hook/hook.py Fri Dec 17 22:40:51 2010 +0100
+++ b/bitbucket_hook/hook.py Sun Dec 19 14:45:44 2010 +0100
@@ -17,28 +17,6 @@
ADDRESS = 'pypy-svn at codespeak.net'
hgexe = str(py.path.local.sysfind('hg'))
-def hg(*argv):
- from subprocess import Popen, PIPE
- argv = map(str, argv)
- proc = Popen([hgexe] + list(argv), stdout=PIPE, stderr=PIPE)
- stdout, stderr = proc.communicate()
- ret = proc.wait()
- if ret != 0:
- print >> sys.stderr, 'error: hg', ' '.join(argv)
- print >> sys.stderr, stderr
- raise Exception('error when executing hg')
- return stdout.decode('utf-8')
-
-def send(from_, to, subject, body):
- import smtplib
- from email.mime.text import MIMEText
-
- smtp = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
- msg = MIMEText(body, _charset='utf-8')
- msg['From'] = from_
- msg['To'] = to
- msg['Subject'] = subject
- smtp.sendmail(from_, [to], msg.as_string())
TEMPLATE = u"""\
Author: {author}
@@ -53,6 +31,33 @@
class BitbucketHookHandler(object):
+ def _hgexe(self, argv):
+ from subprocess import Popen, PIPE
+ proc = Popen([hgexe] + list(argv), stdout=PIPE, stderr=PIPE)
+ stdout, stderr = proc.communicate()
+ ret = proc.wait()
+ return stdout, stderr, ret
+
+ def hg(self, *argv):
+ argv = map(str, argv)
+ stdout, stderr, ret = self._hgexe(argv)
+ if ret != 0:
+ print >> sys.stderr, 'error: hg', ' '.join(argv)
+ print >> sys.stderr, stderr
+ raise Exception('error when executing hg')
+ return stdout.decode('utf-8')
+
+ def send(self, from_, to, subject, body):
+ import smtplib
+ from email.mime.text import MIMEText
+
+ smtp = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
+ msg = MIMEText(body, _charset='utf-8')
+ msg['From'] = from_
+ msg['To'] = to
+ msg['Subject'] = subject
+ smtp.sendmail(from_, [to], msg.as_string())
+
def handle(self, payload):
path = payload['repository']['absolute_url']
self.payload = payload
@@ -61,7 +66,7 @@
if not self.local_repo.check(dir=True):
print >> sys.stderr, 'Ignoring unknown repo', path
return
- hg('pull', '-R', self.local_repo)
+ self.hg('pull', '-R', self.local_repo)
self.handle_diff_email()
def handle_diff_email(self):
@@ -78,11 +83,11 @@
url = self.remote_repo + 'changeset/' + commit['node'] + '/'
template = TEMPLATE % {'url': url}
subject = '%s %s: %s' % (reponame, commit['branch'], line0)
- body = hg('-R', self.local_repo, 'log', '-r', hgid,
+ body = self.hg('-R', self.local_repo, 'log', '-r', hgid,
'--template', template)
diff = self.get_diff(hgid, commit['files'])
body = body+diff
- send(sender, ADDRESS, subject, body)
+ self.send(sender, ADDRESS, subject, body)
def get_diff(self, hgid, files):
import re
@@ -90,8 +95,8 @@
files = [item['file'] for item in files]
lines = []
for filename in files:
- out = hg('-R', self.local_repo, 'diff', '--git', '-c', hgid,
- self.local_repo.join(filename))
+ out = self.hg('-R', self.local_repo, 'diff', '--git', '-c', hgid,
+ self.local_repo.join(filename))
match = binary.search(out)
if match:
# it's a binary patch, omit the content
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bitbucket_hook/test/test_hook.py Sun Dec 19 14:45:44 2010 +0100
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+
+from bitbucket_hook.hook import BitbucketHookHandler
+
+class BaseHandler(BitbucketHookHandler):
+
+ def __init__(self):
+ self.mails = []
+
+ def send(self, from_, to, subject, body):
+ self.mails.append((from_, to, subject, body))
+
+
+def test_non_ascii_encoding():
+ class MyHandler(BaseHandler):
+ def _hgexe(self, argv):
+ return u'späm'.encode('utf-8'), '', 0
+ #
+ handler = MyHandler()
+ stdout = handler.hg('foobar')
+ assert stdout == u'späm'
+
Repository URL: https://bitbucket.org/pypy/buildbot/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the Pypy-commit
mailing list