Use 'unicode_escape' in utils.str.dqrepr if running Python 3.

This commit is contained in:
Valentin Lorentz 2012-08-04 17:33:17 +02:00
parent 0a4a12243d
commit 8af6761275

View File

@ -120,7 +120,8 @@ def dqrepr(s):
"""Returns a repr() of s guaranteed to be in double quotes.""" """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. # The wankers-that-be decided not to use double-quotes anymore in 2.3.
# return '"' + repr("'\x00" + s)[6:] # 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): def quoted(s):
"""Returns a quoted s.""" """Returns a quoted s."""