Mercurial > hg
annotate mercurial/urllibcompat.py @ 51226:83091c14058c
rust-index: avoid some cloning in find_gca_candidates()
Instead of keeping the information whether the current revision is
poisoned on `current_seen`, we extract it as a boolean.
This also allows us to simplify the explanation of `seen[r].is_poisoned()`,
as the exceptional case where it is poisoned right after `r` has been
determined to be a solution does no longer exist.
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Fri, 20 Oct 2023 08:17:00 +0200 |
parents | 18c8c18993f0 |
children | 493034cc3265 |
rev | line source |
---|---|
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 |
34465
80d4681150b9
urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 from . import pycompat |
80d4681150b9
urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
34467
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
16 _sysstr = pycompat.sysstr |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
17 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40159
diff
changeset
|
18 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48896
diff
changeset
|
19 class _pycompatstub: |
34467
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
20 def __init__(self): |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
21 self._aliases = {} |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
22 |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
23 def _registeraliases(self, origin, items): |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
24 """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
|
25 items = map(_sysstr, items) |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
26 self._aliases.update( |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43089
diff
changeset
|
27 (item.replace('_', '').lower(), (origin, item)) for item in items |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40159
diff
changeset
|
28 ) |
34467
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
29 |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
30 def _registeralias(self, origin, attr, name): |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
31 """Alias ``origin``.``attr`` as ``name``""" |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
32 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
|
33 |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
34 def __getattr__(self, name): |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
35 try: |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
36 origin, item = self._aliases[name] |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
37 except KeyError: |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
38 raise AttributeError(name) |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
39 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
|
40 return obj |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
41 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40159
diff
changeset
|
42 |
34467
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
43 httpserver = _pycompatstub() |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
44 urlreq = _pycompatstub() |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
45 urlerr = _pycompatstub() |
192f7b126ed2
urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents:
34465
diff
changeset
|
46 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
47 urlreq._registeraliases( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
48 urllib.parse, |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
49 ( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
50 b"splitattr", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
51 b"splitpasswd", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
52 b"splitport", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
53 b"splituser", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
54 b"urlparse", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
55 b"urlunparse", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
56 ), |
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 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
|
59 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
|
60 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
|
61 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
62 urlreq._registeraliases( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
63 urllib.request, |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
64 ( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
65 b"AbstractHTTPHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
66 b"BaseHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
67 b"build_opener", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
68 b"FileHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
69 b"FTPHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
70 b"ftpwrapper", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
71 b"HTTPHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
72 b"HTTPSHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
73 b"install_opener", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
74 b"pathname2url", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
75 b"HTTPBasicAuthHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
76 b"HTTPDigestAuthHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
77 b"HTTPPasswordMgrWithDefaultRealm", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
78 b"ProxyHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
79 b"Request", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
80 b"url2pathname", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
81 b"urlopen", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
82 ), |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
83 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40159
diff
changeset
|
84 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40159
diff
changeset
|
85 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
86 urlreq._registeraliases( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
87 urllib.response, |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
88 ( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
89 b"addclosehook", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
90 b"addinfourl", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
91 ), |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
92 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40159
diff
changeset
|
93 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
94 urlerr._registeraliases( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
95 urllib.error, |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
96 ( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
97 b"HTTPError", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
98 b"URLError", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
99 ), |
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 httpserver._registeraliases( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
103 http.server, |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
104 ( |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
105 b"HTTPServer", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
106 b"BaseHTTPRequestHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
107 b"SimpleHTTPRequestHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
108 b"CGIHTTPRequestHandler", |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
109 ), |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
110 ) |
46785
521ac0d7047f
typing: disable import error warnings that are already handled
Matt Harbison <matt_harbison@yahoo.com>
parents:
45942
diff
changeset
|
111 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
112 # 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
|
113 # (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
|
114 # 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
|
115 def quote(s, safe='/'): |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
116 # 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
|
117 # 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
|
118 if isinstance(s, pycompat.bytestr): |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
119 s = bytes(s) |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
120 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
|
121 return s.encode('ascii', 'strict') |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
122 |
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 # 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
|
125 # sure we return bytes. |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
126 def urlencode(query, doseq=False): |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
127 s = urllib.parse.urlencode(query, doseq=doseq) |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
128 return s.encode('ascii') |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
129 |
34465
80d4681150b9
urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
131 urlreq.quote = quote |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
132 urlreq.urlencode = urlencode |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
133 |
34465
80d4681150b9
urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
135 def getfullurl(req): |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
136 return req.full_url |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
137 |
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 def gethost(req): |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
140 return req.host |
34465
80d4681150b9
urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
142 |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
143 def getselector(req): |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
144 return req.selector |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
145 |
34465
80d4681150b9
urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
146 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
147 def getdata(req): |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
148 return req.data |
34465
80d4681150b9
urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
149 |
48896
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
150 |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
151 def hasdata(req): |
4286ec1d9842
urllibcompat: remove Python 2 support code
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
152 return req.data is not None |