Patchwork D12364: pycompat: remove json.loads polyfill for Python 3.5

login
register
mail settings
Submitter phabricator
Date March 10, 2022, 1:08 a.m.
Message ID <differential-rev-PHID-DREV-dv2nwopvzjxjck2mqfi7-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50706/
State New
Headers show

Comments

phabricator - March 10, 2022, 1:08 a.m.
indygreg created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We no longer support Python 3.5 so this can be deleted.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D12364

AFFECTED FILES
  mercurial/pycompat.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -376,47 +376,7 @@ 
 iteritems = lambda x: x.items()
 itervalues = lambda x: x.values()
 
-# Python 3.5's json.load and json.loads require str. We polyfill its
-# code for detecting encoding from bytes.
-if sys.version_info[0:2] < (3, 6):
-
-    def _detect_encoding(b):
-        bstartswith = b.startswith
-        if bstartswith((codecs.BOM_UTF32_BE, codecs.BOM_UTF32_LE)):
-            return 'utf-32'
-        if bstartswith((codecs.BOM_UTF16_BE, codecs.BOM_UTF16_LE)):
-            return 'utf-16'
-        if bstartswith(codecs.BOM_UTF8):
-            return 'utf-8-sig'
-
-        if len(b) >= 4:
-            if not b[0]:
-                # 00 00 -- -- - utf-32-be
-                # 00 XX -- -- - utf-16-be
-                return 'utf-16-be' if b[1] else 'utf-32-be'
-            if not b[1]:
-                # XX 00 00 00 - utf-32-le
-                # XX 00 00 XX - utf-16-le
-                # XX 00 XX -- - utf-16-le
-                return 'utf-16-le' if b[2] or b[3] else 'utf-32-le'
-        elif len(b) == 2:
-            if not b[0]:
-                # 00 XX - utf-16-be
-                return 'utf-16-be'
-            if not b[1]:
-                # XX 00 - utf-16-le
-                return 'utf-16-le'
-        # default
-        return 'utf-8'
-
-    def json_loads(s, *args, **kwargs):
-        if isinstance(s, (bytes, bytearray)):
-            s = s.decode(_detect_encoding(s), 'surrogatepass')
-
-        return json.loads(s, *args, **kwargs)
-
-else:
-    json_loads = json.loads
+json_loads = json.loads
 
 isjython = sysplatform.startswith(b'java')