##// END OF EJS Templates
cleanup: use urllibcompat for renamed methods on urllib request objects...
Augie Fackler -
r34467:1232f7fa default
parent child Browse files
Show More
@@ -28,6 +28,7 b' import socket'
28 28 import stat
29 29
30 30 from . import (
31 urllibcompat,
31 32 util,
32 33 )
33 34
@@ -214,8 +215,8 b' class FileRangeHandler(urlreq.filehandle'
214 215 server would.
215 216 """
216 217 def open_local_file(self, req):
217 host = req.get_host()
218 file = req.get_selector()
218 host = urllibcompat.gethost(req)
219 file = urllibcompat.getselector(req)
219 220 localfile = urlreq.url2pathname(file)
220 221 stats = os.stat(localfile)
221 222 size = stats[stat.ST_SIZE]
@@ -252,7 +253,7 b' class FileRangeHandler(urlreq.filehandle'
252 253
253 254 class FTPRangeHandler(urlreq.ftphandler):
254 255 def ftp_open(self, req):
255 host = req.get_host()
256 host = urllibcompat.gethost(req)
256 257 if not host:
257 258 raise IOError('ftp error', 'no host given')
258 259 host, port = splitport(host)
@@ -18,6 +18,7 b' from .i18n import _'
18 18 from . import (
19 19 httpclient,
20 20 sslutil,
21 urllibcompat,
21 22 util,
22 23 )
23 24
@@ -174,13 +175,14 b' class http2handler(urlreq.httphandler, u'
174 175 # object. On Python 2.6.5, it's stored in the _tunnel_host
175 176 # attribute which has no accessor.
176 177 tunhost = getattr(req, '_tunnel_host', None)
177 host = req.get_host()
178 host = urllibcompat.gethost(req)
178 179 if tunhost:
179 180 proxyhost = host
180 181 host = tunhost
181 182 elif req.has_proxy():
182 proxyhost = req.get_host()
183 host = req.get_selector().split('://', 1)[1].split('/', 1)[0]
183 proxyhost = urllibcompat.gethost(req)
184 host = urllibcompat.getselector(
185 req).split('://', 1)[1].split('/', 1)[0]
184 186 else:
185 187 proxyhost = None
186 188
@@ -219,7 +221,7 b' class http2handler(urlreq.httphandler, u'
219 221 headers = dict(
220 222 (name.title(), val) for name, val in headers.items())
221 223 try:
222 path = req.get_selector()
224 path = urllibcompat.getselector(req)
223 225 if '://' in path:
224 226 path = path.split('://', 1)[1].split('/', 1)[1]
225 227 if path[0] != '/':
@@ -233,7 +235,7 b' class http2handler(urlreq.httphandler, u'
233 235 # object initialized properly.
234 236 r.recv = r.read
235 237
236 resp = urlreq.addinfourl(r, r.headers, req.get_full_url())
238 resp = urlreq.addinfourl(r, r.headers, urllibcompat.getfullurl(req))
237 239 resp.code = r.status
238 240 resp.msg = r.reason
239 241 return resp
@@ -242,7 +244,7 b' class http2handler(urlreq.httphandler, u'
242 244 # target, and then allows full URIs in the request path, which it
243 245 # then observes and treats as a signal to do proxying instead.
244 246 def http_open(self, req):
245 if req.get_full_url().startswith('https'):
247 if urllibcompat.getfullurl(req).startswith('https'):
246 248 return self.https_open(req)
247 249 def makehttpcon(*args, **kwargs):
248 250 k2 = dict(kwargs)
@@ -251,9 +253,9 b' class http2handler(urlreq.httphandler, u'
251 253 return self.do_open(makehttpcon, req, False)
252 254
253 255 def https_open(self, req):
254 # req.get_full_url() does not contain credentials and we may
256 # urllibcompat.getfullurl(req) does not contain credentials and we may
255 257 # need them to match the certificates.
256 url = req.get_full_url()
258 url = urllibcompat.getfullurl(req)
257 259 user, password = self.pwmgr.find_stored_password(url)
258 260 res = readauthforuri(self.ui, url, user)
259 261 if res:
@@ -93,6 +93,7 b' import threading'
93 93 from .i18n import _
94 94 from . import (
95 95 pycompat,
96 urllibcompat,
96 97 util,
97 98 )
98 99
@@ -206,7 +207,7 b' class KeepAliveHandler(object):'
206 207 return self.do_open(HTTPConnection, req)
207 208
208 209 def do_open(self, http_class, req):
209 host = req.get_host()
210 host = urllibcompat.gethost(req)
210 211 if not host:
211 212 raise urlerr.urlerror('no host given')
212 213
@@ -317,10 +318,11 b' class KeepAliveHandler(object):'
317 318 if n in headers:
318 319 skipheaders['skip_' + n.replace('-', '_')] = 1
319 320 try:
320 if req.has_data():
321 data = req.get_data()
321 if urllibcompat.hasdata(req):
322 data = urllibcompat.getdata(req)
322 323 h.putrequest(
323 req.get_method(), req.get_selector(), **skipheaders)
324 req.get_method(), urllibcompat.getselector(req),
325 **skipheaders)
324 326 if 'content-type' not in headers:
325 327 h.putheader('Content-type',
326 328 'application/x-www-form-urlencoded')
@@ -328,13 +330,14 b' class KeepAliveHandler(object):'
328 330 h.putheader('Content-length', '%d' % len(data))
329 331 else:
330 332 h.putrequest(
331 req.get_method(), req.get_selector(), **skipheaders)
333 req.get_method(), urllibcompat.getselector(req),
334 **skipheaders)
332 335 except socket.error as err:
333 336 raise urlerr.urlerror(err)
334 337 for k, v in headers.items():
335 338 h.putheader(k, v)
336 339 h.endheaders()
337 if req.has_data():
340 if urllibcompat.hasdata(req):
338 341 h.send(data)
339 342
340 343 class HTTPHandler(KeepAliveHandler, urlreq.httphandler):
@@ -21,6 +21,7 b' from . import ('
21 21 keepalive,
22 22 pycompat,
23 23 sslutil,
24 urllibcompat,
24 25 util,
25 26 )
26 27
@@ -119,7 +120,7 b' class proxyhandler(urlreq.proxyhandler):'
119 120 self.ui = ui
120 121
121 122 def proxy_open(self, req, proxy, type_):
122 host = req.get_host().split(':')[0]
123 host = urllibcompat.gethost(req).split(':')[0]
123 124 for e in self.no_list:
124 125 if host == e:
125 126 return None
@@ -166,10 +167,10 b' def _generic_start_transaction(handler, '
166 167 tunnel_host = 'https://' + tunnel_host
167 168 new_tunnel = True
168 169 else:
169 tunnel_host = req.get_selector()
170 tunnel_host = urllibcompat.getselector(req)
170 171 new_tunnel = False
171 172
172 if new_tunnel or tunnel_host == req.get_full_url(): # has proxy
173 if new_tunnel or tunnel_host == urllibcompat.getfullurl(req): # has proxy
173 174 u = util.url(tunnel_host)
174 175 if new_tunnel or u.scheme == 'https': # only use CONNECT for HTTPS
175 176 h.realhostport = ':'.join([u.host, (u.port or '443')])
@@ -320,9 +321,9 b' if has_https:'
320 321 return keepalive.KeepAliveHandler._start_transaction(self, h, req)
321 322
322 323 def https_open(self, req):
323 # req.get_full_url() does not contain credentials and we may
324 # need them to match the certificates.
325 url = req.get_full_url()
324 # urllibcompat.getfullurl() does not contain credentials
325 # and we may need them to match the certificates.
326 url = urllibcompat.getfullurl(req)
326 327 user, password = self.pwmgr.find_stored_password(url)
327 328 res = httpconnectionmod.readauthforuri(self.ui, url, user)
328 329 if res:
@@ -406,7 +407,8 b' class httpbasicauthhandler(urlreq.httpba'
406 407 self, auth_header, host, req, headers)
407 408
408 409 def retry_http_basic_auth(self, host, req, realm):
409 user, pw = self.passwd.find_user_password(realm, req.get_full_url())
410 user, pw = self.passwd.find_user_password(
411 realm, urllibcompat.getfullurl(req))
410 412 if pw is not None:
411 413 raw = "%s:%s" % (user, pw)
412 414 auth = 'Basic %s' % base64.b64encode(raw).strip()
General Comments 0
You need to be logged in to leave comments. Login now