Mercurial > hg
comparison hgext/bugzilla.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 | 4aa72cdf616f |
children | 9f70512ae2cf |
comparison
equal
deleted
inserted
replaced
43379:bb509f39d387 | 43380:579672b347d2 |
---|---|
953 return url | 953 return url |
954 | 954 |
955 def _fetch(self, burl): | 955 def _fetch(self, burl): |
956 try: | 956 try: |
957 resp = url.open(self.ui, burl) | 957 resp = url.open(self.ui, burl) |
958 return json.loads(resp.read()) | 958 return pycompat.json_loads(resp.read()) |
959 except util.urlerr.httperror as inst: | 959 except util.urlerr.httperror as inst: |
960 if inst.code == 401: | 960 if inst.code == 401: |
961 raise error.Abort(_(b'authorization failed')) | 961 raise error.Abort(_(b'authorization failed')) |
962 if inst.code == 404: | 962 if inst.code == 404: |
963 raise NotFound() | 963 raise NotFound() |
976 else: | 976 else: |
977 request_type = util.urlreq.request | 977 request_type = util.urlreq.request |
978 req = request_type(burl, data, {b'Content-Type': b'application/json'}) | 978 req = request_type(burl, data, {b'Content-Type': b'application/json'}) |
979 try: | 979 try: |
980 resp = url.opener(self.ui).open(req) | 980 resp = url.opener(self.ui).open(req) |
981 return json.loads(resp.read()) | 981 return pycompat.json_loads(resp.read()) |
982 except util.urlerr.httperror as inst: | 982 except util.urlerr.httperror as inst: |
983 if inst.code == 401: | 983 if inst.code == 401: |
984 raise error.Abort(_(b'authorization failed')) | 984 raise error.Abort(_(b'authorization failed')) |
985 if inst.code == 404: | 985 if inst.code == 404: |
986 raise NotFound() | 986 raise NotFound() |