--- a/mercurial/pure/charencode.py Sat Oct 05 10:29:34 2019 -0400
+++ b/mercurial/pure/charencode.py Sun Oct 06 09:45:02 2019 -0400
@@ -9,9 +9,8 @@
import array
-from .. import (
- pycompat,
-)
+from .. import pycompat
+
def isasciistr(s):
try:
@@ -20,6 +19,7 @@
except UnicodeDecodeError:
return False
+
def asciilower(s):
'''convert a string to lowercase if ASCII
@@ -27,6 +27,7 @@
s.decode('ascii')
return s.lower()
+
def asciiupper(s):
'''convert a string to uppercase if ASCII
@@ -34,22 +35,24 @@
s.decode('ascii')
return s.upper()
+
_jsonmap = []
_jsonmap.extend("\\u%04x" % x for x in range(32))
_jsonmap.extend(pycompat.bytechr(x) for x in range(32, 127))
_jsonmap.append('\\u007f')
_jsonmap[0x09] = '\\t'
-_jsonmap[0x0a] = '\\n'
+_jsonmap[0x0A] = '\\n'
_jsonmap[0x22] = '\\"'
-_jsonmap[0x5c] = '\\\\'
+_jsonmap[0x5C] = '\\\\'
_jsonmap[0x08] = '\\b'
-_jsonmap[0x0c] = '\\f'
-_jsonmap[0x0d] = '\\r'
+_jsonmap[0x0C] = '\\f'
+_jsonmap[0x0D] = '\\r'
_paranoidjsonmap = _jsonmap[:]
-_paranoidjsonmap[0x3c] = '\\u003c' # '<' (e.g. escape "</script>")
-_paranoidjsonmap[0x3e] = '\\u003e' # '>'
+_paranoidjsonmap[0x3C] = '\\u003c' # '<' (e.g. escape "</script>")
+_paranoidjsonmap[0x3E] = '\\u003e' # '>'
_jsonmap.extend(pycompat.bytechr(x) for x in range(128, 256))
+
def jsonescapeu8fast(u8chars, paranoid):
"""Convert a UTF-8 byte string to JSON-escaped form (fast path)
@@ -64,11 +67,13 @@
except IndexError:
raise ValueError
+
if pycompat.ispy3:
_utf8strict = r'surrogatepass'
else:
_utf8strict = r'strict'
+
def jsonescapeu8fallback(u8chars, paranoid):
"""Convert a UTF-8 byte string to JSON-escaped form (slow path)