comparison mercurial/httppeer.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 313e3a279828
children 89a2afe31e82
comparison
equal deleted inserted replaced
43505:47fac1692ede 43506:9f70512ae2cf
61 # Note: it is *NOT* a bug that the last bit here is a bytestring 61 # Note: it is *NOT* a bug that the last bit here is a bytestring
62 # and not a unicode: we're just getting the encoded length anyway, 62 # and not a unicode: we're just getting the encoded length anyway,
63 # and using an r-string to make it portable between Python 2 and 3 63 # and using an r-string to make it portable between Python 2 and 3
64 # doesn't work because then the \r is a literal backslash-r 64 # doesn't work because then the \r is a literal backslash-r
65 # instead of a carriage return. 65 # instead of a carriage return.
66 valuelen = limit - len(fmt % r'000') - len(b': \r\n') 66 valuelen = limit - len(fmt % '000') - len(b': \r\n')
67 result = [] 67 result = []
68 68
69 n = 0 69 n = 0
70 for i in pycompat.xrange(0, len(value), valuelen): 70 for i in pycompat.xrange(0, len(value), valuelen):
71 n += 1 71 n += 1
156 i.length = len(data) 156 i.length = len(data)
157 data = i 157 data = i
158 argsio = io.BytesIO(strargs) 158 argsio = io.BytesIO(strargs)
159 argsio.length = len(strargs) 159 argsio.length = len(strargs)
160 data = _multifile(argsio, data) 160 data = _multifile(argsio, data)
161 headers[r'X-HgArgs-Post'] = len(strargs) 161 headers['X-HgArgs-Post'] = len(strargs)
162 elif args: 162 elif args:
163 # Calling self.capable() can infinite loop if we are calling 163 # Calling self.capable() can infinite loop if we are calling
164 # "capabilities". But that command should never accept wire 164 # "capabilities". But that command should never accept wire
165 # protocol arguments. So this should never happen. 165 # protocol arguments. So this should never happen.
166 assert cmd != b'capabilities' 166 assert cmd != b'capabilities'
185 size = 0 185 size = 0
186 if util.safehasattr(data, b'length'): 186 if util.safehasattr(data, b'length'):
187 size = data.length 187 size = data.length
188 elif data is not None: 188 elif data is not None:
189 size = len(data) 189 size = len(data)
190 if data is not None and r'Content-Type' not in headers: 190 if data is not None and 'Content-Type' not in headers:
191 headers[r'Content-Type'] = r'application/mercurial-0.1' 191 headers['Content-Type'] = 'application/mercurial-0.1'
192 192
193 # Tell the server we accept application/mercurial-0.2 and multiple 193 # Tell the server we accept application/mercurial-0.2 and multiple
194 # compression formats if the server is capable of emitting those 194 # compression formats if the server is capable of emitting those
195 # payloads. 195 # payloads.
196 # Note: Keep this set empty by default, as client advertisement of 196 # Note: Keep this set empty by default, as client advertisement of
226 for header, value in protoheaders: 226 for header, value in protoheaders:
227 headers[header] = value 227 headers[header] = value
228 228
229 varyheaders = [] 229 varyheaders = []
230 for header in headers: 230 for header in headers:
231 if header.lower().startswith(r'x-hg'): 231 if header.lower().startswith('x-hg'):
232 varyheaders.append(header) 232 varyheaders.append(header)
233 233
234 if varyheaders: 234 if varyheaders:
235 headers[r'Vary'] = r','.join(sorted(varyheaders)) 235 headers['Vary'] = ','.join(sorted(varyheaders))
236 236
237 req = requestbuilder(pycompat.strurl(cu), data, headers) 237 req = requestbuilder(pycompat.strurl(cu), data, headers)
238 238
239 if data is not None: 239 if data is not None:
240 ui.debug(b"sending %d bytes\n" % size) 240 ui.debug(b"sending %d bytes\n" % size)
241 req.add_unredirected_header(r'Content-Length', r'%d' % size) 241 req.add_unredirected_header('Content-Length', '%d' % size)
242 242
243 return req, cu, qs 243 return req, cu, qs
244 244
245 245
246 def _reqdata(req): 246 def _reqdata(req):
346 redirected = True 346 redirected = True
347 if not ui.quiet: 347 if not ui.quiet:
348 ui.warn(_(b'real URL is %s\n') % respurl) 348 ui.warn(_(b'real URL is %s\n') % respurl)
349 349
350 try: 350 try:
351 proto = pycompat.bytesurl(resp.getheader(r'content-type', r'')) 351 proto = pycompat.bytesurl(resp.getheader('content-type', ''))
352 except AttributeError: 352 except AttributeError:
353 proto = pycompat.bytesurl(resp.headers.get(r'content-type', r'')) 353 proto = pycompat.bytesurl(resp.headers.get('content-type', ''))
354 354
355 safeurl = util.hidepassword(baseurl) 355 safeurl = util.hidepassword(baseurl)
356 if proto.startswith(b'application/hg-error'): 356 if proto.startswith(b'application/hg-error'):
357 raise error.OutOfBandError(resp.read()) 357 raise error.OutOfBandError(resp.read())
358 358
515 type = x 515 type = x
516 break 516 break
517 517
518 tempname = bundle2.writebundle(self.ui, cg, None, type) 518 tempname = bundle2.writebundle(self.ui, cg, None, type)
519 fp = httpconnection.httpsendfile(self.ui, tempname, b"rb") 519 fp = httpconnection.httpsendfile(self.ui, tempname, b"rb")
520 headers = {r'Content-Type': r'application/mercurial-0.1'} 520 headers = {'Content-Type': 'application/mercurial-0.1'}
521 521
522 try: 522 try:
523 r = self._call(cmd, data=fp, headers=headers, **args) 523 r = self._call(cmd, data=fp, headers=headers, **args)
524 vals = r.split(b'\n', 1) 524 vals = r.split(b'\n', 1)
525 if len(vals) < 2: 525 if len(vals) < 2:
548 while d: 548 while d:
549 fh.write(d) 549 fh.write(d)
550 d = fp.read(4096) 550 d = fp.read(4096)
551 # start http push 551 # start http push
552 with httpconnection.httpsendfile(self.ui, filename, b"rb") as fp_: 552 with httpconnection.httpsendfile(self.ui, filename, b"rb") as fp_:
553 headers = {r'Content-Type': r'application/mercurial-0.1'} 553 headers = {'Content-Type': 'application/mercurial-0.1'}
554 return self._callstream(cmd, data=fp_, headers=headers, **args) 554 return self._callstream(cmd, data=fp_, headers=headers, **args)
555 finally: 555 finally:
556 if filename is not None: 556 if filename is not None:
557 os.unlink(filename) 557 os.unlink(filename)
558 558
619 # TODO stream this. 619 # TODO stream this.
620 body = b''.join(map(bytes, handler.flushcommands())) 620 body = b''.join(map(bytes, handler.flushcommands()))
621 621
622 # TODO modify user-agent to reflect v2 622 # TODO modify user-agent to reflect v2
623 headers = { 623 headers = {
624 r'Accept': wireprotov2server.FRAMINGTYPE, 624 'Accept': wireprotov2server.FRAMINGTYPE,
625 r'Content-Type': wireprotov2server.FRAMINGTYPE, 625 'Content-Type': wireprotov2server.FRAMINGTYPE,
626 } 626 }
627 627
628 req = requestbuilder(pycompat.strurl(url), body, headers) 628 req = requestbuilder(pycompat.strurl(url), body, headers)
629 req.add_unredirected_header(r'Content-Length', r'%d' % len(body)) 629 req.add_unredirected_header('Content-Length', '%d' % len(body))
630 630
631 try: 631 try:
632 res = opener.open(req) 632 res = opener.open(req)
633 except urlerr.httperror as e: 633 except urlerr.httperror as e:
634 if e.code == 401: 634 if e.code == 401:
963 # now. 963 # now.
964 advertisev2 = ui.configbool(b'experimental', b'httppeer.advertise-v2') 964 advertisev2 = ui.configbool(b'experimental', b'httppeer.advertise-v2')
965 965
966 if advertisev2: 966 if advertisev2:
967 args[b'headers'] = { 967 args[b'headers'] = {
968 r'X-HgProto-1': r'cbor', 968 'X-HgProto-1': 'cbor',
969 } 969 }
970 970
971 args[b'headers'].update( 971 args[b'headers'].update(
972 encodevalueinheaders( 972 encodevalueinheaders(
973 b' '.join(sorted(API_PEERS)), 973 b' '.join(sorted(API_PEERS)),