From 6c0497d34e7015414b6b00fdd80b5d5cc0fd5bb4 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 23 Jan 2013 13:53:37 +0100 Subject: [PATCH] Fix traceback when utils.str.dqrepr is given a unicode object. --- src/utils/str.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/str.py b/src/utils/str.py index 16a44ae34..5392fa548 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -144,6 +144,8 @@ def dqrepr(s): # The wankers-that-be decided not to use double-quotes anymore in 2.3. # return '"' + repr("'\x00" + s)[6:] 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('"', '\\"') def quoted(s):