Mercurial > public > mercurial-scm > hg
comparison mercurial/url.py @ 46907:ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
The new module is well fitting for this new code. And this will be useful to
make the gathered code collaborate more later.
Differential Revision: https://phab.mercurial-scm.org/D10374
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 12 Apr 2021 03:01:04 +0200 |
parents | d4ba4d51f85f |
children | 8e5192e41e0b |
comparison
equal
deleted
inserted
replaced
46906:33524c46a092 | 46907:ffd3e823a7e5 |
---|---|
24 pycompat, | 24 pycompat, |
25 sslutil, | 25 sslutil, |
26 urllibcompat, | 26 urllibcompat, |
27 util, | 27 util, |
28 ) | 28 ) |
29 from .utils import stringutil | 29 from .utils import ( |
30 stringutil, | |
31 urlutil, | |
32 ) | |
30 | 33 |
31 httplib = util.httplib | 34 httplib = util.httplib |
32 stringio = util.stringio | 35 stringio = util.stringio |
33 urlerr = util.urlerr | 36 urlerr = util.urlerr |
34 urlreq = util.urlreq | 37 urlreq = util.urlreq |
73 if res: | 76 if res: |
74 group, auth = res | 77 group, auth = res |
75 user, passwd = auth.get(b'username'), auth.get(b'password') | 78 user, passwd = auth.get(b'username'), auth.get(b'password') |
76 self.ui.debug(b"using auth.%s.* for authentication\n" % group) | 79 self.ui.debug(b"using auth.%s.* for authentication\n" % group) |
77 if not user or not passwd: | 80 if not user or not passwd: |
78 u = util.url(pycompat.bytesurl(authuri)) | 81 u = urlutil.url(pycompat.bytesurl(authuri)) |
79 u.query = None | 82 u.query = None |
80 if not self.ui.interactive(): | 83 if not self.ui.interactive(): |
81 raise error.Abort( | 84 raise error.Abort( |
82 _(b'http authorization required for %s') | 85 _(b'http authorization required for %s') |
83 % util.hidepassword(bytes(u)) | 86 % urlutil.hidepassword(bytes(u)) |
84 ) | 87 ) |
85 | 88 |
86 self.ui.write( | 89 self.ui.write( |
87 _(b"http authorization required for %s\n") | 90 _(b"http authorization required for %s\n") |
88 % util.hidepassword(bytes(u)) | 91 % urlutil.hidepassword(bytes(u)) |
89 ) | 92 ) |
90 self.ui.write(_(b"realm: %s\n") % pycompat.bytesurl(realm)) | 93 self.ui.write(_(b"realm: %s\n") % pycompat.bytesurl(realm)) |
91 if user: | 94 if user: |
92 self.ui.write(_(b"user: %s\n") % user) | 95 self.ui.write(_(b"user: %s\n") % user) |
93 else: | 96 else: |
126 # proxy can be proper url or host[:port] | 129 # proxy can be proper url or host[:port] |
127 if not ( | 130 if not ( |
128 proxyurl.startswith(b'http:') or proxyurl.startswith(b'https:') | 131 proxyurl.startswith(b'http:') or proxyurl.startswith(b'https:') |
129 ): | 132 ): |
130 proxyurl = b'http://' + proxyurl + b'/' | 133 proxyurl = b'http://' + proxyurl + b'/' |
131 proxy = util.url(proxyurl) | 134 proxy = urlutil.url(proxyurl) |
132 if not proxy.user: | 135 if not proxy.user: |
133 proxy.user = ui.config(b"http_proxy", b"user") | 136 proxy.user = ui.config(b"http_proxy", b"user") |
134 proxy.passwd = ui.config(b"http_proxy", b"passwd") | 137 proxy.passwd = ui.config(b"http_proxy", b"passwd") |
135 | 138 |
136 # see if we should use a proxy for this url | 139 # see if we should use a proxy for this url |
153 | 156 |
154 # Keys and values need to be str because the standard library | 157 # Keys and values need to be str because the standard library |
155 # expects them to be. | 158 # expects them to be. |
156 proxyurl = str(proxy) | 159 proxyurl = str(proxy) |
157 proxies = {'http': proxyurl, 'https': proxyurl} | 160 proxies = {'http': proxyurl, 'https': proxyurl} |
158 ui.debug(b'proxying through %s\n' % util.hidepassword(bytes(proxy))) | 161 ui.debug( |
162 b'proxying through %s\n' % urlutil.hidepassword(bytes(proxy)) | |
163 ) | |
159 else: | 164 else: |
160 proxies = {} | 165 proxies = {} |
161 | 166 |
162 urlreq.proxyhandler.__init__(self, proxies) | 167 urlreq.proxyhandler.__init__(self, proxies) |
163 self.ui = ui | 168 self.ui = ui |
217 else: | 222 else: |
218 tunnel_host = urllibcompat.getselector(req) | 223 tunnel_host = urllibcompat.getselector(req) |
219 new_tunnel = False | 224 new_tunnel = False |
220 | 225 |
221 if new_tunnel or tunnel_host == urllibcompat.getfullurl(req): # has proxy | 226 if new_tunnel or tunnel_host == urllibcompat.getfullurl(req): # has proxy |
222 u = util.url(pycompat.bytesurl(tunnel_host)) | 227 u = urlutil.url(pycompat.bytesurl(tunnel_host)) |
223 if new_tunnel or u.scheme == b'https': # only use CONNECT for HTTPS | 228 if new_tunnel or u.scheme == b'https': # only use CONNECT for HTTPS |
224 h.realhostport = b':'.join([u.host, (u.port or b'443')]) | 229 h.realhostport = b':'.join([u.host, (u.port or b'443')]) |
225 h.headers = req.headers.copy() | 230 h.headers = req.headers.copy() |
226 h.headers.update(handler.parent.addheaders) | 231 h.headers.update(handler.parent.addheaders) |
227 return | 232 return |
673 | 678 |
674 return opener | 679 return opener |
675 | 680 |
676 | 681 |
677 def open(ui, url_, data=None, sendaccept=True): | 682 def open(ui, url_, data=None, sendaccept=True): |
678 u = util.url(url_) | 683 u = urlutil.url(url_) |
679 if u.scheme: | 684 if u.scheme: |
680 u.scheme = u.scheme.lower() | 685 u.scheme = u.scheme.lower() |
681 url_, authinfo = u.authinfo() | 686 url_, authinfo = u.authinfo() |
682 else: | 687 else: |
683 path = util.normpath(os.path.abspath(url_)) | 688 path = util.normpath(os.path.abspath(url_)) |