[PATCH 2 of 7] encoding: use double backslash

Gregory Szorc gregory.szorc at gmail.com
Sun Dec 13 01:34:12 CST 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1449991572 28800
#      Sat Dec 12 23:26:12 2015 -0800
# Node ID 12538d67af89c3e64892cff0a374dc022b111959
# Parent  1ff97720b3f5c35f3ec9192947f809459962db9f
encoding: use double backslash

In Python 2, '\u' == '\\u'. However, in Python 3, '\u' results in:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in
position 0-1: truncated \uXXXX escape

The minor change in this patch allows Python 3 to ast parse encoding.py.

diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -406,9 +406,9 @@ def jsonescape(s):
     '''
 
     if not _jsonmap:
         for x in xrange(32):
-            _jsonmap[chr(x)] = "\u%04x" %x
+            _jsonmap[chr(x)] = "\\u%04x" % x
         for x in xrange(32, 256):
             c = chr(x)
             _jsonmap[c] = c
         _jsonmap['\t'] = '\\t'


More information about the Mercurial-devel mailing list