Fix traceback when utils.str.dqrepr is given a unicode object.

This commit is contained in:
Valentin Lorentz 2013-01-23 13:53:37 +01:00
parent 6ea1347d3d
commit 6c0497d34e

View File

@ -144,6 +144,8 @@ def dqrepr(s):
# The wankers-that-be decided not to use double-quotes anymore in 2.3. # The wankers-that-be decided not to use double-quotes anymore in 2.3.
# return '"' + repr("'\x00" + s)[6:] # return '"' + repr("'\x00" + s)[6:]
encoding = 'string_escape' if sys.version_info[0] < 3 else 'unicode_escape' encoding = 'string_escape' if sys.version_info[0] < 3 else 'unicode_escape'
if sys.version_info[0] < 3 and isinstance(s, unicode):
s = s.encode('utf8', 'replace')
return '"%s"' % s.encode(encoding).decode().replace('"', '\\"') return '"%s"' % s.encode(encoding).decode().replace('"', '\\"')
def quoted(s): def quoted(s):