Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

buildlogger: make everything unicode

  • Loading branch information...
commit 5c8053463a38a8c554e0d8a02bef8e5942df8aee 1 parent 7c024a1
Dan Crosta authored
Showing with 21 additions and 0 deletions.
  1. +2 −0  buildscripts/buildlogger.py
  2. +19 −0 buildscripts/utils.py
2  buildscripts/buildlogger.py
View
@@ -32,6 +32,7 @@
import time
import traceback
import urllib2
+import utils
try:
import json
@@ -322,6 +323,7 @@ def handle_sigterm(signum, frame):
while proc.poll() is None:
try:
line = proc.stdout.readline().strip('\r\n')
+ line = utils.unicode_dammit(line)
callback(line)
except IOError:
# if the signal handler is called while
19 buildscripts/utils.py
View
@@ -1,4 +1,5 @@
+import codecs
import re
import socket
import time
@@ -191,3 +192,21 @@ def run_smoke_command(*args):
# otherwise SCons treats it as a list of dependencies.
return [smoke_command(*args)]
+# unicode is a pain. some strings cannot be unicode()'d
+# but we want to just preserve the bytes in a human-readable
+# fashion. this codec error handler will substitute the
+# repr() of the offending bytes into the decoded string
+# at the position they occurred
+def replace_with_repr(unicode_error):
+ offender = unicode_error.object[unicode_error.start:unicode_error.end]
+ return (unicode(repr(offender).strip("'").strip('"')), unicode_error.end)
+
+codecs.register_error('repr', replace_with_repr)
+
+def unicode_dammit(string, encoding='utf8'):
+ # convert a string to a unicode, using the Python
+ # representation of non-ascii bytes when necessary
+ #
+ # name inpsired by BeautifulSoup's "UnicodeDammit"
+ return string.decode(encoding, 'repr')
+
Please sign in to comment.
Something went wrong with that request. Please try again.