mercurial/urllibcompat.py
author Matt Harbison <matt_harbison@yahoo.com>
Sat, 19 Aug 2023 23:06:40 -0400
changeset 50824 489268c8ee7e
parent 48946 642e31cb55f0
child 50929 18c8c18993f0
permissions -rw-r--r--
cmdutil: migrate `opts` on commitstatus() to native kwargs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34465
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
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
     8
import http.server
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
     9
import urllib.error
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    10
import urllib.parse
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    11
import urllib.request
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    12
import urllib.response
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    13
43089
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
    14
from .pycompat import getattr
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
from . import pycompat
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    17
_sysstr = pycompat.sysstr
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    18
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
    19
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48896
diff changeset
    20
class _pycompatstub:
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    21
    def __init__(self):
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    22
        self._aliases = {}
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    23
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    24
    def _registeraliases(self, origin, items):
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    25
        """Add items that will be populated at the first access"""
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    26
        items = map(_sysstr, items)
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    27
        self._aliases.update(
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43089
diff changeset
    28
            (item.replace('_', '').lower(), (origin, item)) for item in items
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
    29
        )
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    30
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    31
    def _registeralias(self, origin, attr, name):
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    32
        """Alias ``origin``.``attr`` as ``name``"""
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    33
        self._aliases[_sysstr(name)] = (origin, _sysstr(attr))
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    34
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    35
    def __getattr__(self, name):
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    36
        try:
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    37
            origin, item = self._aliases[name]
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    38
        except KeyError:
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    39
            raise AttributeError(name)
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    40
        self.__dict__[name] = obj = getattr(origin, item)
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    41
        return obj
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    42
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
    43
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    44
httpserver = _pycompatstub()
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    45
urlreq = _pycompatstub()
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    46
urlerr = _pycompatstub()
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
    47
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    48
urlreq._registeraliases(
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    49
    urllib.parse,
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    50
    (
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    51
        b"splitattr",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    52
        b"splitpasswd",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    53
        b"splitport",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    54
        b"splituser",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    55
        b"urlparse",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    56
        b"urlunparse",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    57
    ),
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    58
)
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    59
urlreq._registeralias(urllib.parse, b"parse_qs", b"parseqs")
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    60
urlreq._registeralias(urllib.parse, b"parse_qsl", b"parseqsl")
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    61
urlreq._registeralias(urllib.parse, b"unquote_to_bytes", b"unquote")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
    62
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    63
urlreq._registeraliases(
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    64
    urllib.request,
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    65
    (
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    66
        b"AbstractHTTPHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    67
        b"BaseHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    68
        b"build_opener",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    69
        b"FileHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    70
        b"FTPHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    71
        b"ftpwrapper",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    72
        b"HTTPHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    73
        b"HTTPSHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    74
        b"install_opener",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    75
        b"pathname2url",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    76
        b"HTTPBasicAuthHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    77
        b"HTTPDigestAuthHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    78
        b"HTTPPasswordMgrWithDefaultRealm",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    79
        b"ProxyHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    80
        b"Request",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    81
        b"url2pathname",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    82
        b"urlopen",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    83
    ),
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    84
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
    85
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
    86
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    87
urlreq._registeraliases(
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    88
    urllib.response,
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    89
    (
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    90
        b"addclosehook",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    91
        b"addinfourl",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    92
    ),
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    93
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
    94
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    95
urlerr._registeraliases(
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    96
    urllib.error,
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    97
    (
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    98
        b"HTTPError",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
    99
        b"URLError",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   100
    ),
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   101
)
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   102
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   103
httpserver._registeraliases(
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   104
    http.server,
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   105
    (
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   106
        b"HTTPServer",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   107
        b"BaseHTTPRequestHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   108
        b"SimpleHTTPRequestHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   109
        b"CGIHTTPRequestHandler",
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   110
    ),
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   111
)
46785
521ac0d7047f typing: disable import error warnings that are already handled
Matt Harbison <matt_harbison@yahoo.com>
parents: 45942
diff changeset
   112
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   113
# urllib.parse.quote() accepts both str and bytes, decodes bytes
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   114
# (if necessary), and returns str. This is wonky. We provide a custom
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   115
# implementation that only accepts bytes and emits bytes.
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   116
def quote(s, safe='/'):
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   117
    # bytestr has an __iter__ that emits characters. quote_from_bytes()
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   118
    # does an iteration and expects ints. We coerce to bytes to appease it.
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   119
    if isinstance(s, pycompat.bytestr):
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   120
        s = bytes(s)
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   121
    s = urllib.parse.quote_from_bytes(s, safe=safe)
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   122
    return s.encode('ascii', 'strict')
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   123
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   124
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   125
# urllib.parse.urlencode() returns str. We use this function to make
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   126
# sure we return bytes.
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   127
def urlencode(query, doseq=False):
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   128
    s = urllib.parse.urlencode(query, doseq=doseq)
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   129
    return s.encode('ascii')
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   130
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
   131
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   132
urlreq.quote = quote
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   133
urlreq.urlencode = urlencode
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   134
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
   135
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   136
def getfullurl(req):
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   137
    return req.full_url
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   138
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   139
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   140
def gethost(req):
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   141
    return req.host
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
   142
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   143
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   144
def getselector(req):
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   145
    return req.selector
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   146
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
   147
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   148
def getdata(req):
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   149
    return req.data
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
   150
48896
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   151
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   152
def hasdata(req):
4286ec1d9842 urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
   153
    return req.data is not None