diff options
author | Dan Crosta <dcrosta@10gen.com> | 2012-04-10 13:38:37 -0400 |
---|---|---|
committer | Dan Crosta <dcrosta@10gen.com> | 2012-04-10 16:39:48 -0400 |
commit | 6fcb4179839fcfa94fc219407d617558419208a7 (patch) | |
tree | 5cbe7225112455883bd855de612415836cb68e9e /buildscripts/buildlogger.py | |
parent | 8b4d9dbe20e0f3f75a62d5ababe12e50f1d935ab (diff) | |
download | mongo-6fcb4179839fcfa94fc219407d617558419208a7.tar.gz |
be explicit about encodings in buildlogger
Diffstat (limited to 'buildscripts/buildlogger.py')
-rw-r--r-- | buildscripts/buildlogger.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/buildscripts/buildlogger.py b/buildscripts/buildlogger.py index d025a0717f6..a6f91d840f8 100644 --- a/buildscripts/buildlogger.py +++ b/buildscripts/buildlogger.py @@ -25,6 +25,7 @@ test, in order to let the buildlogs web app display the full output sensibly.) import functools import os import os.path +import re import signal import subprocess import sys @@ -84,16 +85,22 @@ def url(endpoint): return '%s/%s' % (URL_ROOT.rstrip('/'), endpoint) def post(endpoint, data, headers=None): - data = json.dumps(data) + data = json.dumps(data, encoding='utf-8') headers = headers or {} - headers.update({'Content-Type': 'application/json'}) + headers.update({'Content-Type': 'application/json; charset=utf-8'}) req = urllib2.Request(url=url(endpoint), data=data, headers=headers) response = url_opener.open(req, timeout=TIMEOUT_SECONDS) response_headers = dict(response.info()) - if response_headers.get('content-type') == 'application/json': - return json.load(response) + + # eg "Content-Type: application/json; charset=utf-8" + content_type = response_headers.get('content-type') + match = re.match(r'(?P<mimetype>[^;]+).*(?:charset=(?P<charset>[^ ]+))?$', content_type) + if match and match.group('mimetype') == 'application/json': + encoding = match.group('charset') or 'utf-8' + return json.load(response, encoding=encoding) + return response.read() def traceback_to_stderr(func): |