py3: byteify the decoded JSON responses upon receipt in the LFS blobstore
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 27 Jan 2019 17:48:15 -0500
changeset 41451 7df10ea7a5b8
parent 41450 4045ab21945a
child 41452 52a4a3e7cc6a
py3: byteify the decoded JSON responses upon receipt in the LFS blobstore It got too confusing juggling r'' vs b'' across several functions.
hgext/lfs/blobstore.py
--- a/hgext/lfs/blobstore.py	Sun Jan 27 18:05:17 2019 -0500
+++ b/hgext/lfs/blobstore.py	Sun Jan 27 17:48:15 2019 -0500
@@ -307,7 +307,7 @@
         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 @@
                                          separators=(r'', r': '),
                                          sort_keys=True)))
 
-        return response
+        def encodestr(x):
+            if isinstance(x, pycompat.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 @@
         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 @@
             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: