From 8af676127527b64852a952c987d1b4c2488a702f Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 4 Aug 2012 17:33:17 +0200 Subject: [PATCH] Use 'unicode_escape' in utils.str.dqrepr if running Python 3. --- src/utils/str.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/str.py b/src/utils/str.py index eb5561231..ff48e4739 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -120,7 +120,8 @@ def dqrepr(s): """Returns a repr() of s guaranteed to be in double quotes.""" # The wankers-that-be decided not to use double-quotes anymore in 2.3. # return '"' + repr("'\x00" + s)[6:] - return '"%s"' % s.encode('string_escape').replace('"', '\\"') + encoding = 'string_escape' if sys.version_info[0] < 3 else 'unicode_escape' + return '"%s"' % s.encode(encoding).decode().replace('"', '\\"') def quoted(s): """Returns a quoted s."""