[PATCH 07 of 11] py3: byteify the decoded JSON responses upon receipt in the LFS blobstore
Matt Harbison
mharbison72 at gmail.com
Mon Jan 28 05:20:53 UTC 2019
# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1548629295 18000
# Sun Jan 27 17:48:15 2019 -0500
# Node ID b98988169d4a9c7890b93091683fa4ec38d61a47
# Parent 1d6f4c32abc28ea54e3d1d8487a1d773033aedf0
py3: byteify the decoded JSON responses upon receipt in the LFS blobstore
It got too confusing juggling r'' vs b'' across several functions.
diff --git a/hgext/lfs/blobstore.py b/hgext/lfs/blobstore.py
--- a/hgext/lfs/blobstore.py
+++ b/hgext/lfs/blobstore.py
@@ -307,7 +307,7 @@ class _gitlfsremote(object):
except util.urlerr.httperror as ex:
hints = {
400: _(b'check that lfs serving is enabled on %s and "%s" is '
- 'supported') % (self.baseurl, action),
+ b'supported') % (self.baseurl, action),
404: _(b'the "lfs.url" config may be used to override %s')
% self.baseurl,
}
@@ -342,7 +342,12 @@ class _gitlfsremote(object):
separators=(r'', r': '),
sort_keys=True)))
- return response
+ def encodestr(x):
+ if isinstance(x, unicode):
+ return x.encode(u'utf-8')
+ return x
+
+ return pycompat.rapply(encodestr, response)
def _checkforservererror(self, pointers, responses, action):
"""Scans errors from objects
@@ -410,12 +415,11 @@ class _gitlfsremote(object):
See https://github.com/git-lfs/git-lfs/blob/master/docs/api/\
basic-transfers.md
"""
- oid = pycompat.bytestr(obj['oid'])
+ oid = obj[b'oid']
+ href = obj[b'actions'][action].get(b'href')
+ headers = obj[b'actions'][action].get(b'header', {}).items()
- href = pycompat.bytestr(obj['actions'][action].get('href'))
- headers = obj['actions'][action].get('header', {}).items()
-
- request = util.urlreq.request(href)
+ request = util.urlreq.request(pycompat.strurl(href))
if action == b'upload':
# If uploading blobs, read data from local blobstore.
if not localstore.verify(oid):
@@ -426,7 +430,7 @@ class _gitlfsremote(object):
request.add_header(r'Content-Type', r'application/octet-stream')
for k, v in headers:
- request.add_header(k, v)
+ request.add_header(pycompat.strurl(k), pycompat.strurl(v))
response = b''
try:
More information about the Mercurial-devel
mailing list