comparison mercurial/httppeer.py @ 37738:a1f785148097

httppeer: work around API differences on urllib Request objects Since this is only a problem in httppeer, I'd rather keep this a local-to-the-module kludge rather than pile more on pycompat. We'll still find it easily to clean up later because it checks pycompat.ispy3. Differential Revision: https://phab.mercurial-scm.org/D3347
author Augie Fackler <augie@google.com>
date Fri, 13 Apr 2018 21:11:28 -0400
parents 6cb7e3b91883
children 856f381ad74b
comparison
equal deleted inserted replaced
37737:6cb7e3b91883 37738:a1f785148097
262 ui.debug("sending %d bytes\n" % size) 262 ui.debug("sending %d bytes\n" % size)
263 req.add_unredirected_header(r'Content-Length', r'%d' % size) 263 req.add_unredirected_header(r'Content-Length', r'%d' % size)
264 264
265 return req, cu, qs 265 return req, cu, qs
266 266
267 def _reqdata(req):
268 """Get request data, if any. If no data, returns None."""
269 if pycompat.ispy3:
270 return req.data
271 if not req.has_data():
272 return None
273 return req.get_data()
274
267 def sendrequest(ui, opener, req): 275 def sendrequest(ui, opener, req):
268 """Send a prepared HTTP request. 276 """Send a prepared HTTP request.
269 277
270 Returns the response object. 278 Returns the response object.
271 """ 279 """
288 dbg(line % ' %s %s' % (header, value)) 296 dbg(line % ' %s %s' % (header, value))
289 297
290 if hgargssize is not None: 298 if hgargssize is not None:
291 dbg(line % ' %d bytes of commands arguments in headers' 299 dbg(line % ' %d bytes of commands arguments in headers'
292 % hgargssize) 300 % hgargssize)
293 301 data = _reqdata(req)
294 if req.has_data(): 302 if data is not None:
295 data = req.get_data()
296 length = getattr(data, 'length', None) 303 length = getattr(data, 'length', None)
297 if length is None: 304 if length is None:
298 length = len(data) 305 length = len(data)
299 dbg(line % ' %d bytes of data' % length) 306 dbg(line % ' %d bytes of data' % length)
300 307