annotate mercurial/urllibcompat.py @ 45796:e9555305c5c6

templates: include all non-branch namespaces in default one-line summary I left out branches and custom namespaces on purpose from D9252 because I figured that people like us (Google) who have custom namespaces can also have custom configs. However, I just realized that this makes everyone with the topic extension lose the topic they've had in rebase output for a long time (ever since someone was nice enough to add it in D741). Sorry about the churn. The more generic template couldn't easily keep the "log.bookmark" label in the template because the namespace is called "bookmarks" (plural). That means that we can't be compatible with users' existing configs for "log.bookmark", so I decided to change the labels to be in a brand-new "oneline-summary" namespace. Differential Revision: https://phab.mercurial-scm.org/D9262
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 29 Oct 2020 09:03:08 -0700
parents 9f70512ae2cf
children 89a2afe31e82
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 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
43089
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
9 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
10 from . import pycompat
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
11
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
12 _sysstr = pycompat.sysstr
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
13
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
14
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
15 class _pycompatstub(object):
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
16 def __init__(self):
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
17 self._aliases = {}
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
18
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
19 def _registeraliases(self, origin, items):
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
20 """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
21 items = map(_sysstr, items)
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
22 self._aliases.update(
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43089
diff changeset
23 (item.replace('_', '').lower(), (origin, item)) for item in items
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
24 )
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
25
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
26 def _registeralias(self, origin, attr, name):
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
27 """Alias ``origin``.``attr`` as ``name``"""
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
28 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
29
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
30 def __getattr__(self, name):
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
31 try:
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
32 origin, item = self._aliases[name]
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
33 except KeyError:
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
34 raise AttributeError(name)
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
35 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
36 return obj
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
37
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
38
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
39 httpserver = _pycompatstub()
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
40 urlreq = _pycompatstub()
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
41 urlerr = _pycompatstub()
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
42
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
43 if pycompat.ispy3:
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
44 import urllib.parse
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
45
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
46 urlreq._registeraliases(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
47 urllib.parse,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
48 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
49 b"splitattr",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
50 b"splitpasswd",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
51 b"splitport",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
52 b"splituser",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
53 b"urlparse",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
54 b"urlunparse",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
55 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
56 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
57 urlreq._registeralias(urllib.parse, b"parse_qs", b"parseqs")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
58 urlreq._registeralias(urllib.parse, b"parse_qsl", b"parseqsl")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
59 urlreq._registeralias(urllib.parse, b"unquote_to_bytes", b"unquote")
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
60 import urllib.request
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
61
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
62 urlreq._registeraliases(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
63 urllib.request,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
64 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
65 b"AbstractHTTPHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
66 b"BaseHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
67 b"build_opener",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
68 b"FileHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
69 b"FTPHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
70 b"ftpwrapper",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
71 b"HTTPHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
72 b"HTTPSHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
73 b"install_opener",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
74 b"pathname2url",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
75 b"HTTPBasicAuthHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
76 b"HTTPDigestAuthHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
77 b"HTTPPasswordMgrWithDefaultRealm",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
78 b"ProxyHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
79 b"Request",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
80 b"url2pathname",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
81 b"urlopen",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
82 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
83 )
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
84 import urllib.response
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
85
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
86 urlreq._registeraliases(urllib.response, (b"addclosehook", b"addinfourl",))
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
87 import urllib.error
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
88
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
89 urlerr._registeraliases(urllib.error, (b"HTTPError", b"URLError",))
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
90 import http.server
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
91
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
92 httpserver._registeraliases(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
93 http.server,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
94 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
95 b"HTTPServer",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
96 b"BaseHTTPRequestHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
97 b"SimpleHTTPRequestHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
98 b"CGIHTTPRequestHandler",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
99 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
100 )
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
101
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
102 # urllib.parse.quote() accepts both str and bytes, decodes bytes
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
103 # (if necessary), and returns str. This is wonky. We provide a custom
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
104 # implementation that only accepts bytes and emits bytes.
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43089
diff changeset
105 def quote(s, safe='/'):
40159
5774fc623a18 py3: coerce bytestr to bytes to appease urllib.parse.quote_from_bytes()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36835
diff changeset
106 # bytestr has an __iter__ that emits characters. quote_from_bytes()
5774fc623a18 py3: coerce bytestr to bytes to appease urllib.parse.quote_from_bytes()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36835
diff changeset
107 # does an iteration and expects ints. We coerce to bytes to appease it.
5774fc623a18 py3: coerce bytestr to bytes to appease urllib.parse.quote_from_bytes()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36835
diff changeset
108 if isinstance(s, pycompat.bytestr):
5774fc623a18 py3: coerce bytestr to bytes to appease urllib.parse.quote_from_bytes()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36835
diff changeset
109 s = bytes(s)
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
110 s = urllib.parse.quote_from_bytes(s, safe=safe)
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
111 return s.encode('ascii', 'strict')
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
112
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
113 # urllib.parse.urlencode() returns str. We use this function to make
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
114 # sure we return bytes.
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
115 def urlencode(query, doseq=False):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
116 s = urllib.parse.urlencode(query, doseq=doseq)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
117 return s.encode('ascii')
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
118
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
119 urlreq.quote = quote
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
120 urlreq.urlencode = urlencode
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
121
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
122 def getfullurl(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
123 return req.full_url
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
124
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
125 def gethost(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
126 return req.host
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
127
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
128 def getselector(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
129 return req.selector
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
130
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
131 def getdata(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
132 return req.data
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
133
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
134 def hasdata(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
135 return req.data is not None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
136
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
137
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
138 else:
34467
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
139 import BaseHTTPServer
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
140 import CGIHTTPServer
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
141 import SimpleHTTPServer
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
142 import urllib2
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
143 import urllib
192f7b126ed2 urllibcompat: move some adapters from pycompat to urllibcompat
Augie Fackler <augie@google.com>
parents: 34465
diff changeset
144 import urlparse
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
145
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
146 urlreq._registeraliases(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
147 urllib,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
148 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
149 b"addclosehook",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
150 b"addinfourl",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
151 b"ftpwrapper",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
152 b"pathname2url",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
153 b"quote",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
154 b"splitattr",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
155 b"splitpasswd",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
156 b"splitport",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
157 b"splituser",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
158 b"unquote",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
159 b"url2pathname",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
160 b"urlencode",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
161 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
162 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
163 urlreq._registeraliases(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
164 urllib2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
165 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
166 b"AbstractHTTPHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
167 b"BaseHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
168 b"build_opener",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
169 b"FileHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
170 b"FTPHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
171 b"HTTPBasicAuthHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
172 b"HTTPDigestAuthHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
173 b"HTTPHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
174 b"HTTPPasswordMgrWithDefaultRealm",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
175 b"HTTPSHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
176 b"install_opener",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
177 b"ProxyHandler",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
178 b"Request",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
179 b"urlopen",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
180 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
181 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
182 urlreq._registeraliases(urlparse, (b"urlparse", b"urlunparse",))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
183 urlreq._registeralias(urlparse, b"parse_qs", b"parseqs")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
184 urlreq._registeralias(urlparse, b"parse_qsl", b"parseqsl")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
185 urlerr._registeraliases(urllib2, (b"HTTPError", b"URLError",))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
186 httpserver._registeraliases(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
187 BaseHTTPServer, (b"HTTPServer", b"BaseHTTPRequestHandler",)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40159
diff changeset
188 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
189 httpserver._registeraliases(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
190 SimpleHTTPServer, (b"SimpleHTTPRequestHandler",)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
191 )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
192 httpserver._registeraliases(CGIHTTPServer, (b"CGIHTTPRequestHandler",))
34465
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
193
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
194 def gethost(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
195 return req.get_host()
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
196
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
197 def getselector(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
198 return req.get_selector()
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
199
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
200 def getfullurl(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
201 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
202
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
203 def getdata(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
204 return req.get_data()
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
205
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
206 def hasdata(req):
80d4681150b9 urllibcompat: new library to help abstract out some python3 urllib2 stuff
Augie Fackler <augie@google.com>
parents:
diff changeset
207 return req.has_data()