comparison hgext/lfs/blobstore.py @ 43506:9f70512ae2cf

cleanup: remove pointless r-prefixes on single-quoted strings This is the promised second step on single-quoted strings. These had existed because our source transformer didn't turn r'' into b'', so we had tagged some strings as r-strings to get "native" strings on both Pythons. Now that the transformer is gone, we can dispense with this nonsense. Methodology: I ran hg locate 'set:added() or modified() or clean()' | egrep '.*\.py$' | xargs egrep --color=never -n -- \[\^b\]\[\^a-z\]r\'\[\^\'\\\\\]\*\'\[\^\'\ in an emacs grep-mode buffer, and then used a keyboard macro to iterate over the results and remove the r prefix as needed. # skip-blame removing unneeded r prefixes left over from Python 3 migration. Differential Revision: https://phab.mercurial-scm.org/D7306
author Augie Fackler <augie@google.com>
date Fri, 08 Nov 2019 11:19:20 -0800
parents 579672b347d2
children 05881d002cb2
comparison
equal deleted inserted replaced
43505:47fac1692ede 43506:9f70512ae2cf
278 278
279 def http_error_401(self, req, fp, code, msg, headers): 279 def http_error_401(self, req, fp, code, msg, headers):
280 """Enforces that any authentication performed is HTTP Basic 280 """Enforces that any authentication performed is HTTP Basic
281 Authentication. No authentication is also acceptable. 281 Authentication. No authentication is also acceptable.
282 """ 282 """
283 authreq = headers.get(r'www-authenticate', None) 283 authreq = headers.get('www-authenticate', None)
284 if authreq: 284 if authreq:
285 scheme = authreq.split()[0] 285 scheme = authreq.split()[0]
286 286
287 if scheme.lower() != r'basic': 287 if scheme.lower() != 'basic':
288 msg = _(b'the server must support Basic Authentication') 288 msg = _(b'the server must support Basic Authentication')
289 raise util.urlerr.httperror( 289 raise util.urlerr.httperror(
290 req.get_full_url(), 290 req.get_full_url(),
291 code, 291 code,
292 encoding.strfromlocal(msg), 292 encoding.strfromlocal(msg),
322 322
323 Return decoded JSON object like {'objects': [{'oid': '', 'size': 1}]} 323 Return decoded JSON object like {'objects': [{'oid': '', 'size': 1}]}
324 See https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md 324 See https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
325 """ 325 """
326 objects = [ 326 objects = [
327 {r'oid': pycompat.strurl(p.oid()), r'size': p.size()} 327 {'oid': pycompat.strurl(p.oid()), 'size': p.size()}
328 for p in pointers 328 for p in pointers
329 ] 329 ]
330 requestdata = pycompat.bytesurl( 330 requestdata = pycompat.bytesurl(
331 json.dumps( 331 json.dumps(
332 {r'objects': objects, r'operation': pycompat.strurl(action),} 332 {'objects': objects, 'operation': pycompat.strurl(action),}
333 ) 333 )
334 ) 334 )
335 url = b'%s/objects/batch' % self.baseurl 335 url = b'%s/objects/batch' % self.baseurl
336 batchreq = util.urlreq.request(pycompat.strurl(url), data=requestdata) 336 batchreq = util.urlreq.request(pycompat.strurl(url), data=requestdata)
337 batchreq.add_header(r'Accept', r'application/vnd.git-lfs+json') 337 batchreq.add_header('Accept', 'application/vnd.git-lfs+json')
338 batchreq.add_header(r'Content-Type', r'application/vnd.git-lfs+json') 338 batchreq.add_header('Content-Type', 'application/vnd.git-lfs+json')
339 try: 339 try:
340 with contextlib.closing(self.urlopener.open(batchreq)) as rsp: 340 with contextlib.closing(self.urlopener.open(batchreq)) as rsp:
341 rawjson = rsp.read() 341 rawjson = rsp.read()
342 except util.urlerr.httperror as ex: 342 except util.urlerr.httperror as ex:
343 hints = { 343 hints = {
374 self.ui.debug(b'Status: %d\n' % rsp.status) 374 self.ui.debug(b'Status: %d\n' % rsp.status)
375 # lfs-test-server and hg serve return headers in different order 375 # lfs-test-server and hg serve return headers in different order
376 headers = pycompat.bytestr(rsp.info()).strip() 376 headers = pycompat.bytestr(rsp.info()).strip()
377 self.ui.debug(b'%s\n' % b'\n'.join(sorted(headers.splitlines()))) 377 self.ui.debug(b'%s\n' % b'\n'.join(sorted(headers.splitlines())))
378 378
379 if r'objects' in response: 379 if 'objects' in response:
380 response[r'objects'] = sorted( 380 response['objects'] = sorted(
381 response[r'objects'], key=lambda p: p[r'oid'] 381 response['objects'], key=lambda p: p['oid']
382 ) 382 )
383 self.ui.debug( 383 self.ui.debug(
384 b'%s\n' 384 b'%s\n'
385 % pycompat.bytesurl( 385 % pycompat.bytesurl(
386 json.dumps( 386 json.dumps(
387 response, 387 response,
388 indent=2, 388 indent=2,
389 separators=(r'', r': '), 389 separators=('', ': '),
390 sort_keys=True, 390 sort_keys=True,
391 ) 391 )
392 ) 392 )
393 ) 393 )
394 394
481 _(b'detected corrupt lfs object: %s') % oid, 481 _(b'detected corrupt lfs object: %s') % oid,
482 hint=_(b'run hg verify'), 482 hint=_(b'run hg verify'),
483 ) 483 )
484 request.data = filewithprogress(localstore.open(oid), None) 484 request.data = filewithprogress(localstore.open(oid), None)
485 request.get_method = lambda: r'PUT' 485 request.get_method = lambda: r'PUT'
486 request.add_header(r'Content-Type', r'application/octet-stream') 486 request.add_header('Content-Type', 'application/octet-stream')
487 request.add_header(r'Content-Length', len(request.data)) 487 request.add_header('Content-Length', len(request.data))
488 488
489 for k, v in headers: 489 for k, v in headers:
490 request.add_header(pycompat.strurl(k), pycompat.strurl(v)) 490 request.add_header(pycompat.strurl(k), pycompat.strurl(v))
491 491
492 response = b'' 492 response = b''