comparison mercurial/pycompat.py @ 31569:e68932dfbb55

pycompat: define urlreq.urlparse and urlreq.unparse aliases Currently, we export urlparse via util.urlparse then call util.urlparse.urlparse() and util.urlparse.urlunparse() in a few places. This is the only url* module exported from pycompat, making it a one-off. So let's transition to urlreq to match everything else. Yes, we double import "urlparse" now on Python 2. This will be cleaned up in a subsequent patch. Also, the Python 3 functions trade in str/unicode not bytes. So we'll likely need to write a custom implementation that speaks bytes. But moving everyone to an abstracted API is a good first step.
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 21 Mar 2017 22:34:17 -0700
parents 6c9772867344
children 55c6788c54e2
comparison
equal deleted inserted replaced
31568:6c9772867344 31569:e68932dfbb55
285 import BaseHTTPServer 285 import BaseHTTPServer
286 import CGIHTTPServer 286 import CGIHTTPServer
287 import SimpleHTTPServer 287 import SimpleHTTPServer
288 import urllib2 288 import urllib2
289 import urllib 289 import urllib
290 import urlparse
290 urlreq._registeraliases(urllib, ( 291 urlreq._registeraliases(urllib, (
291 "addclosehook", 292 "addclosehook",
292 "addinfourl", 293 "addinfourl",
293 "ftpwrapper", 294 "ftpwrapper",
294 "pathname2url", 295 "pathname2url",
315 "install_opener", 316 "install_opener",
316 "ProxyHandler", 317 "ProxyHandler",
317 "Request", 318 "Request",
318 "urlopen", 319 "urlopen",
319 )) 320 ))
321 urlreq._registeraliases(urlparse, (
322 "urlparse",
323 "urlunparse",
324 ))
320 urlerr._registeraliases(urllib2, ( 325 urlerr._registeraliases(urllib2, (
321 "HTTPError", 326 "HTTPError",
322 "URLError", 327 "URLError",
323 )) 328 ))
324 httpserver._registeraliases(BaseHTTPServer, ( 329 httpserver._registeraliases(BaseHTTPServer, (
337 urlreq._registeraliases(urllib.parse, ( 342 urlreq._registeraliases(urllib.parse, (
338 "splitattr", 343 "splitattr",
339 "splitpasswd", 344 "splitpasswd",
340 "splitport", 345 "splitport",
341 "splituser", 346 "splituser",
347 "urlparse",
348 "urlunparse",
342 )) 349 ))
343 urlreq._registeralias(urllib.parse, "unquote_to_bytes", "unquote") 350 urlreq._registeralias(urllib.parse, "unquote_to_bytes", "unquote")
344 import urllib.request 351 import urllib.request
345 urlreq._registeraliases(urllib.request, ( 352 urlreq._registeraliases(urllib.request, (
346 "AbstractHTTPHandler", 353 "AbstractHTTPHandler",