mercurial/urllibcompat.py
changeset 43077 687b865b95ad
parent 43076 2372284d9457
child 43089 c59eb1560c44
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
    43     import urllib.parse
    43     import urllib.parse
    44 
    44 
    45     urlreq._registeraliases(
    45     urlreq._registeraliases(
    46         urllib.parse,
    46         urllib.parse,
    47         (
    47         (
    48             "splitattr",
    48             b"splitattr",
    49             "splitpasswd",
    49             b"splitpasswd",
    50             "splitport",
    50             b"splitport",
    51             "splituser",
    51             b"splituser",
    52             "urlparse",
    52             b"urlparse",
    53             "urlunparse",
    53             b"urlunparse",
    54         ),
    54         ),
    55     )
    55     )
    56     urlreq._registeralias(urllib.parse, "parse_qs", "parseqs")
    56     urlreq._registeralias(urllib.parse, b"parse_qs", b"parseqs")
    57     urlreq._registeralias(urllib.parse, "parse_qsl", "parseqsl")
    57     urlreq._registeralias(urllib.parse, b"parse_qsl", b"parseqsl")
    58     urlreq._registeralias(urllib.parse, "unquote_to_bytes", "unquote")
    58     urlreq._registeralias(urllib.parse, b"unquote_to_bytes", b"unquote")
    59     import urllib.request
    59     import urllib.request
    60 
    60 
    61     urlreq._registeraliases(
    61     urlreq._registeraliases(
    62         urllib.request,
    62         urllib.request,
    63         (
    63         (
    64             "AbstractHTTPHandler",
    64             b"AbstractHTTPHandler",
    65             "BaseHandler",
    65             b"BaseHandler",
    66             "build_opener",
    66             b"build_opener",
    67             "FileHandler",
    67             b"FileHandler",
    68             "FTPHandler",
    68             b"FTPHandler",
    69             "ftpwrapper",
    69             b"ftpwrapper",
    70             "HTTPHandler",
    70             b"HTTPHandler",
    71             "HTTPSHandler",
    71             b"HTTPSHandler",
    72             "install_opener",
    72             b"install_opener",
    73             "pathname2url",
    73             b"pathname2url",
    74             "HTTPBasicAuthHandler",
    74             b"HTTPBasicAuthHandler",
    75             "HTTPDigestAuthHandler",
    75             b"HTTPDigestAuthHandler",
    76             "HTTPPasswordMgrWithDefaultRealm",
    76             b"HTTPPasswordMgrWithDefaultRealm",
    77             "ProxyHandler",
    77             b"ProxyHandler",
    78             "Request",
    78             b"Request",
    79             "url2pathname",
    79             b"url2pathname",
    80             "urlopen",
    80             b"urlopen",
    81         ),
    81         ),
    82     )
    82     )
    83     import urllib.response
    83     import urllib.response
    84 
    84 
    85     urlreq._registeraliases(urllib.response, ("addclosehook", "addinfourl",))
    85     urlreq._registeraliases(urllib.response, (b"addclosehook", b"addinfourl",))
    86     import urllib.error
    86     import urllib.error
    87 
    87 
    88     urlerr._registeraliases(urllib.error, ("HTTPError", "URLError",))
    88     urlerr._registeraliases(urllib.error, (b"HTTPError", b"URLError",))
    89     import http.server
    89     import http.server
    90 
    90 
    91     httpserver._registeraliases(
    91     httpserver._registeraliases(
    92         http.server,
    92         http.server,
    93         (
    93         (
    94             "HTTPServer",
    94             b"HTTPServer",
    95             "BaseHTTPRequestHandler",
    95             b"BaseHTTPRequestHandler",
    96             "SimpleHTTPRequestHandler",
    96             b"SimpleHTTPRequestHandler",
    97             "CGIHTTPRequestHandler",
    97             b"CGIHTTPRequestHandler",
    98         ),
    98         ),
    99     )
    99     )
   100 
   100 
   101     # urllib.parse.quote() accepts both str and bytes, decodes bytes
   101     # urllib.parse.quote() accepts both str and bytes, decodes bytes
   102     # (if necessary), and returns str. This is wonky. We provide a custom
   102     # (if necessary), and returns str. This is wonky. We provide a custom
   143     import urlparse
   143     import urlparse
   144 
   144 
   145     urlreq._registeraliases(
   145     urlreq._registeraliases(
   146         urllib,
   146         urllib,
   147         (
   147         (
   148             "addclosehook",
   148             b"addclosehook",
   149             "addinfourl",
   149             b"addinfourl",
   150             "ftpwrapper",
   150             b"ftpwrapper",
   151             "pathname2url",
   151             b"pathname2url",
   152             "quote",
   152             b"quote",
   153             "splitattr",
   153             b"splitattr",
   154             "splitpasswd",
   154             b"splitpasswd",
   155             "splitport",
   155             b"splitport",
   156             "splituser",
   156             b"splituser",
   157             "unquote",
   157             b"unquote",
   158             "url2pathname",
   158             b"url2pathname",
   159             "urlencode",
   159             b"urlencode",
   160         ),
   160         ),
   161     )
   161     )
   162     urlreq._registeraliases(
   162     urlreq._registeraliases(
   163         urllib2,
   163         urllib2,
   164         (
   164         (
   165             "AbstractHTTPHandler",
   165             b"AbstractHTTPHandler",
   166             "BaseHandler",
   166             b"BaseHandler",
   167             "build_opener",
   167             b"build_opener",
   168             "FileHandler",
   168             b"FileHandler",
   169             "FTPHandler",
   169             b"FTPHandler",
   170             "HTTPBasicAuthHandler",
   170             b"HTTPBasicAuthHandler",
   171             "HTTPDigestAuthHandler",
   171             b"HTTPDigestAuthHandler",
   172             "HTTPHandler",
   172             b"HTTPHandler",
   173             "HTTPPasswordMgrWithDefaultRealm",
   173             b"HTTPPasswordMgrWithDefaultRealm",
   174             "HTTPSHandler",
   174             b"HTTPSHandler",
   175             "install_opener",
   175             b"install_opener",
   176             "ProxyHandler",
   176             b"ProxyHandler",
   177             "Request",
   177             b"Request",
   178             "urlopen",
   178             b"urlopen",
   179         ),
   179         ),
   180     )
   180     )
   181     urlreq._registeraliases(urlparse, ("urlparse", "urlunparse",))
   181     urlreq._registeraliases(urlparse, (b"urlparse", b"urlunparse",))
   182     urlreq._registeralias(urlparse, "parse_qs", "parseqs")
   182     urlreq._registeralias(urlparse, b"parse_qs", b"parseqs")
   183     urlreq._registeralias(urlparse, "parse_qsl", "parseqsl")
   183     urlreq._registeralias(urlparse, b"parse_qsl", b"parseqsl")
   184     urlerr._registeraliases(urllib2, ("HTTPError", "URLError",))
   184     urlerr._registeraliases(urllib2, (b"HTTPError", b"URLError",))
   185     httpserver._registeraliases(
   185     httpserver._registeraliases(
   186         BaseHTTPServer, ("HTTPServer", "BaseHTTPRequestHandler",)
   186         BaseHTTPServer, (b"HTTPServer", b"BaseHTTPRequestHandler",)
   187     )
   187     )
   188     httpserver._registeraliases(SimpleHTTPServer, ("SimpleHTTPRequestHandler",))
   188     httpserver._registeraliases(
   189     httpserver._registeraliases(CGIHTTPServer, ("CGIHTTPRequestHandler",))
   189         SimpleHTTPServer, (b"SimpleHTTPRequestHandler",)
       
   190     )
       
   191     httpserver._registeraliases(CGIHTTPServer, (b"CGIHTTPRequestHandler",))
   190 
   192 
   191     def gethost(req):
   193     def gethost(req):
   192         return req.get_host()
   194         return req.get_host()
   193 
   195 
   194     def getselector(req):
   196     def getselector(req):