diff hgext/fix.py @ 43380:579672b347d2 stable

py3: define and use json.loads polyfill Python 3.5's json.loads() requires a str. Only Python 3.6+ supports passing a bytes or bytearray. This commit implements a json.loads() polyfill on Python 3.5 so that we can use bytes. The added function to detect encodings comes verbatim from Python 3.7.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 02 Nov 2019 12:09:35 -0700
parents f02d3c0eed18
children b2f95f9d3588 61881b170140
line wrap: on
line diff
--- a/hgext/fix.py	Sat Nov 02 11:48:38 2019 -0700
+++ b/hgext/fix.py	Sat Nov 02 12:09:35 2019 -0700
@@ -126,7 +126,6 @@
 
 import collections
 import itertools
-import json
 import os
 import re
 import subprocess
@@ -642,7 +641,7 @@
             if fixer.shouldoutputmetadata():
                 try:
                     metadatajson, newerdata = stdout.split(b'\0', 1)
-                    metadata[fixername] = json.loads(metadatajson)
+                    metadata[fixername] = pycompat.json_loads(metadatajson)
                 except ValueError:
                     ui.warn(
                         _(b'ignored invalid output from fixer tool: %s\n')