Mercurial > hg
changeset 34465:80d4681150b9
urllibcompat: new library to help abstract out some python3 urllib2 stuff
Doing a new file instead of pycompat because I'm starting to feel like
pycompat is getting a little enormous in terms of scope.
Differential Revision: https://phab.mercurial-scm.org/D890
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 01 Oct 2017 10:45:03 -0400 |
parents | b0910102e495 |
children | 1232f7fa00c3 |
files | mercurial/urllibcompat.py |
diffstat | 1 files changed, 42 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/urllibcompat.py Sun Oct 01 10:45:03 2017 -0400 @@ -0,0 +1,42 @@ +# urllibcompat.py - adapters to ease using urllib2 on Py2 and urllib on Py3 +# +# Copyright 2017 Google, Inc. +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. +from __future__ import absolute_import + +from . import pycompat + +if pycompat.ispy3: + + def getfullurl(req): + return req.full_url + + def gethost(req): + return req.host + + def getselector(req): + return req.selector + + def getdata(req): + return req.data + + def hasdata(req): + return req.data is not None +else: + + def gethost(req): + return req.get_host() + + def getselector(req): + return req.get_selector() + + def getfullurl(req): + return req.get_full_url() + + def getdata(req): + return req.get_data() + + def hasdata(req): + return req.has_data()