mercurial/urllibcompat.py
author Augie Fackler <augie@google.com>
Sun, 01 Oct 2017 10:45:03 -0400
changeset 34466 80d4681150b9
child 34468 192f7b126ed2
permissions -rw-r--r--
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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34466
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
# urllibcompat.py - adapters to ease using urllib2 on Py2 and urllib on Py3
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
#
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
# Copyright 2017 Google, Inc.
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
#
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
from __future__ import absolute_import
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
from . import pycompat
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
if pycompat.ispy3:
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    12
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
    def getfullurl(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
        return req.full_url
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
    def gethost(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    17
        return req.host
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
    def getselector(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
        return req.selector
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
    def getdata(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
        return req.data
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
    def hasdata(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
        return req.data is not None
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
else:
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
    def gethost(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
        return req.get_host()
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    31
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
    def getselector(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
        return req.get_selector()
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    35
    def getfullurl(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
        return req.get_full_url()
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
    def getdata(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
        return req.get_data()
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
    def hasdata(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
        return req.has_data()