Mercurial > hg
comparison hgext/lfs/blobstore.py @ 41429:7df10ea7a5b8
py3: byteify the decoded JSON responses upon receipt in the LFS blobstore
It got too confusing juggling r'' vs b'' across several functions.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 27 Jan 2019 17:48:15 -0500 |
parents | 40efcf78f3df |
children | 0b636d1720a0 |
comparison
equal
deleted
inserted
replaced
41428:4045ab21945a | 41429:7df10ea7a5b8 |
---|---|
305 with contextlib.closing(self.urlopener.open(batchreq)) as rsp: | 305 with contextlib.closing(self.urlopener.open(batchreq)) as rsp: |
306 rawjson = rsp.read() | 306 rawjson = rsp.read() |
307 except util.urlerr.httperror as ex: | 307 except util.urlerr.httperror as ex: |
308 hints = { | 308 hints = { |
309 400: _(b'check that lfs serving is enabled on %s and "%s" is ' | 309 400: _(b'check that lfs serving is enabled on %s and "%s" is ' |
310 'supported') % (self.baseurl, action), | 310 b'supported') % (self.baseurl, action), |
311 404: _(b'the "lfs.url" config may be used to override %s') | 311 404: _(b'the "lfs.url" config may be used to override %s') |
312 % self.baseurl, | 312 % self.baseurl, |
313 } | 313 } |
314 hint = hints.get(ex.code, _(b'api=%s, action=%s') % (url, action)) | 314 hint = hints.get(ex.code, _(b'api=%s, action=%s') % (url, action)) |
315 raise LfsRemoteError( | 315 raise LfsRemoteError( |
340 % pycompat.bytesurl( | 340 % pycompat.bytesurl( |
341 json.dumps(response, indent=2, | 341 json.dumps(response, indent=2, |
342 separators=(r'', r': '), | 342 separators=(r'', r': '), |
343 sort_keys=True))) | 343 sort_keys=True))) |
344 | 344 |
345 return response | 345 def encodestr(x): |
346 if isinstance(x, pycompat.unicode): | |
347 return x.encode(u'utf-8') | |
348 return x | |
349 | |
350 return pycompat.rapply(encodestr, response) | |
346 | 351 |
347 def _checkforservererror(self, pointers, responses, action): | 352 def _checkforservererror(self, pointers, responses, action): |
348 """Scans errors from objects | 353 """Scans errors from objects |
349 | 354 |
350 Raises LfsRemoteError if any objects have an error""" | 355 Raises LfsRemoteError if any objects have an error""" |
408 localstore: blobstore.local | 413 localstore: blobstore.local |
409 | 414 |
410 See https://github.com/git-lfs/git-lfs/blob/master/docs/api/\ | 415 See https://github.com/git-lfs/git-lfs/blob/master/docs/api/\ |
411 basic-transfers.md | 416 basic-transfers.md |
412 """ | 417 """ |
413 oid = pycompat.bytestr(obj['oid']) | 418 oid = obj[b'oid'] |
414 | 419 href = obj[b'actions'][action].get(b'href') |
415 href = pycompat.bytestr(obj['actions'][action].get('href')) | 420 headers = obj[b'actions'][action].get(b'header', {}).items() |
416 headers = obj['actions'][action].get('header', {}).items() | 421 |
417 | 422 request = util.urlreq.request(pycompat.strurl(href)) |
418 request = util.urlreq.request(href) | |
419 if action == b'upload': | 423 if action == b'upload': |
420 # If uploading blobs, read data from local blobstore. | 424 # If uploading blobs, read data from local blobstore. |
421 if not localstore.verify(oid): | 425 if not localstore.verify(oid): |
422 raise error.Abort(_(b'detected corrupt lfs object: %s') % oid, | 426 raise error.Abort(_(b'detected corrupt lfs object: %s') % oid, |
423 hint=_(b'run hg verify')) | 427 hint=_(b'run hg verify')) |
424 request.data = filewithprogress(localstore.open(oid), None) | 428 request.data = filewithprogress(localstore.open(oid), None) |
425 request.get_method = lambda: r'PUT' | 429 request.get_method = lambda: r'PUT' |
426 request.add_header(r'Content-Type', r'application/octet-stream') | 430 request.add_header(r'Content-Type', r'application/octet-stream') |
427 | 431 |
428 for k, v in headers: | 432 for k, v in headers: |
429 request.add_header(k, v) | 433 request.add_header(pycompat.strurl(k), pycompat.strurl(v)) |
430 | 434 |
431 response = b'' | 435 response = b'' |
432 try: | 436 try: |
433 with contextlib.closing(self.urlopener.open(request)) as req: | 437 with contextlib.closing(self.urlopener.open(request)) as req: |
434 ui = self.ui # Shorten debug lines | 438 ui = self.ui # Shorten debug lines |