Details
Details
- Reviewers
Alphare - Group Reviewers
hg-reviewers - Commits
- rHGb677bccf74b9: charencode: remove Python 2 support code
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
( )
Alphare |
hg-reviewers |
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/pure/charencode.py (5 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
cac366c0a398 | b2576ebf63e7 | Gregory Szorc | Feb 21 2022, 12:47 PM |
else: | else: | ||||
jm = _jsonmap | jm = _jsonmap | ||||
try: | try: | ||||
return b''.join(jm[x] for x in bytearray(u8chars)) | return b''.join(jm[x] for x in bytearray(u8chars)) | ||||
except IndexError: | except IndexError: | ||||
raise ValueError | raise ValueError | ||||
if pycompat.ispy3: | |||||
_utf8strict = r'surrogatepass' | _utf8strict = r'surrogatepass' | ||||
else: | |||||
_utf8strict = r'strict' | |||||
def jsonescapeu8fallback(u8chars, paranoid): | def jsonescapeu8fallback(u8chars, paranoid): | ||||
"""Convert a UTF-8 byte string to JSON-escaped form (slow path) | """Convert a UTF-8 byte string to JSON-escaped form (slow path) | ||||
Escapes all non-ASCII characters no matter if paranoid is False. | Escapes all non-ASCII characters no matter if paranoid is False. | ||||
""" | """ | ||||
if paranoid: | if paranoid: | ||||
jm = _paranoidjsonmap | jm = _paranoidjsonmap | ||||
else: | else: | ||||
jm = _jsonmap | jm = _jsonmap | ||||
# non-BMP char is represented as UTF-16 surrogate pair | # non-BMP char is represented as UTF-16 surrogate pair | ||||
u16b = u8chars.decode('utf-8', _utf8strict).encode('utf-16', _utf8strict) | u16b = u8chars.decode('utf-8', _utf8strict).encode('utf-16', _utf8strict) | ||||
u16codes = array.array('H', u16b) | u16codes = array.array('H', u16b) | ||||
u16codes.pop(0) # drop BOM | u16codes.pop(0) # drop BOM | ||||
return b''.join(jm[x] if x < 128 else b'\\u%04x' % x for x in u16codes) | return b''.join(jm[x] if x < 128 else b'\\u%04x' % x for x in u16codes) |