Mercurial > hg-stable
changeset 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 | ce4ae9ead9e7 |
files | mercurial/httppeer.py |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/httppeer.py Fri Apr 13 21:07:18 2018 -0400 +++ b/mercurial/httppeer.py Fri Apr 13 21:11:28 2018 -0400 @@ -264,6 +264,14 @@ return req, cu, qs +def _reqdata(req): + """Get request data, if any. If no data, returns None.""" + if pycompat.ispy3: + return req.data + if not req.has_data(): + return None + return req.get_data() + def sendrequest(ui, opener, req): """Send a prepared HTTP request. @@ -290,9 +298,8 @@ if hgargssize is not None: dbg(line % ' %d bytes of commands arguments in headers' % hgargssize) - - if req.has_data(): - data = req.get_data() + data = _reqdata(req) + if data is not None: length = getattr(data, 'length', None) if length is None: length = len(data)