annotate mercurial/pycompat.py @ 30032:2219f4f82ede

pycompat: extract function that converts attribute or encoding name to str This will be used to convert encoding.encoding to a str acceptable by Python 3 functions. The source encoding is changed to "latin-1" because encoding.encoding can have arbitrary bytes. Since valid names should consist of ASCII characters, we don't care about the mapping of non-ASCII characters so long as invalid names are distinct from valid names.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 28 Sep 2016 22:32:09 +0900
parents 0f6d6fdd3c2a
children f3a1089654e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28818
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
1 # pycompat.py - portability shim for python 3
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
2 #
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
3 # This software may be used and distributed according to the terms of the
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
4 # GNU General Public License version 2 or any later version.
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
5
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
6 """Mercurial portability shim for python 3.
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
7
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
8 This contains aliases to hide python version-specific details from the core.
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
9 """
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
10
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
11 from __future__ import absolute_import
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
12
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
13 import sys
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
14
30030
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
15 ispy3 = (sys.version_info[0] >= 3)
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
16
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
17 if not ispy3:
29324
b501579147f1 py3: conditionalize cPickle import by adding in util
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28882
diff changeset
18 import cPickle as pickle
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
19 import cStringIO as io
29455
0c741fd6158a py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29433
diff changeset
20 import httplib
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
21 import Queue as _queue
29433
33770d2b6cf9 py3: conditionalize SocketServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29432
diff changeset
22 import SocketServer as socketserver
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
23 import urlparse
29432
34b914ac573e py3: conditionalize xmlrpclib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29431
diff changeset
24 import xmlrpclib
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
25 else:
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
26 import http.client as httplib
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
27 import io
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
28 import pickle
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
29 import queue as _queue
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
30 import socketserver
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
31 import urllib.parse as urlparse
29432
34b914ac573e py3: conditionalize xmlrpclib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29431
diff changeset
32 import xmlrpc.client as xmlrpclib
29431
80880ad3fccd py3: conditionalize the urlparse import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29414
diff changeset
33
30030
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
34 if ispy3:
29797
965c91bad9e3 py3: move xrange alias next to import lines
Yuya Nishihara <yuya@tcha.org>
parents: 29779
diff changeset
35 import builtins
29799
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
36 import functools
29797
965c91bad9e3 py3: move xrange alias next to import lines
Yuya Nishihara <yuya@tcha.org>
parents: 29779
diff changeset
37
30032
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
38 def sysstr(s):
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
39 """Return a keyword str to be passed to Python functions such as
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
40 getattr() and str.encode()
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
41
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
42 This never raises UnicodeDecodeError. Non-ascii characters are
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
43 considered invalid and mapped to arbitrary but unique code points
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
44 such that 'sysstr(a) != sysstr(b)' for all 'a != b'.
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
45 """
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
46 if isinstance(s, builtins.str):
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
47 return s
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
48 return s.decode(u'latin-1')
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
49
29799
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
50 def _wrapattrfunc(f):
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
51 @functools.wraps(f)
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
52 def w(object, name, *args):
30032
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
53 return f(object, sysstr(name), *args)
29799
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
54 return w
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
55
29800
178c89e8519a py3: import builtin wrappers automagically by code transformer
Yuya Nishihara <yuya@tcha.org>
parents: 29799
diff changeset
56 # these wrappers are automagically imported by hgloader
29799
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
57 delattr = _wrapattrfunc(builtins.delattr)
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
58 getattr = _wrapattrfunc(builtins.getattr)
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
59 hasattr = _wrapattrfunc(builtins.hasattr)
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
60 setattr = _wrapattrfunc(builtins.setattr)
29800
178c89e8519a py3: import builtin wrappers automagically by code transformer
Yuya Nishihara <yuya@tcha.org>
parents: 29799
diff changeset
61 xrange = builtins.range
29799
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
62
30032
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
63 else:
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
64 def sysstr(s):
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
65 return s
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30030
diff changeset
66
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
67 stringio = io.StringIO
28818
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
68 empty = _queue.Empty
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
69 queue = _queue.Queue
28834
2fac032c1269 pycompat: alias xrange to range in py3
timeless <timeless@mozdev.org>
parents: 28833
diff changeset
70
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
71 class _pycompatstub(object):
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
72 def __init__(self):
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
73 self._aliases = {}
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
74
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
75 def _registeraliases(self, origin, items):
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
76 """Add items that will be populated at the first access"""
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
77 self._aliases.update((item.replace('_', '').lower(), (origin, item))
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
78 for item in items)
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
79
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
80 def __getattr__(self, name):
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
81 try:
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
82 origin, item = self._aliases[name]
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
83 except KeyError:
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
84 raise AttributeError(name)
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
85 self.__dict__[name] = obj = getattr(origin, item)
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
86 return obj
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
87
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
88 httpserver = _pycompatstub()
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
89 urlreq = _pycompatstub()
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
90 urlerr = _pycompatstub()
30030
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
91 if not ispy3:
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
92 import BaseHTTPServer
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
93 import CGIHTTPServer
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
94 import SimpleHTTPServer
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
95 import urllib2
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
96 import urllib
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
97 urlreq._registeraliases(urllib, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
98 "addclosehook",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
99 "addinfourl",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
100 "ftpwrapper",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
101 "pathname2url",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
102 "quote",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
103 "splitattr",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
104 "splitpasswd",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
105 "splitport",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
106 "splituser",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
107 "unquote",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
108 "url2pathname",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
109 "urlencode",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
110 ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
111 urlreq._registeraliases(urllib2, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
112 "AbstractHTTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
113 "BaseHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
114 "build_opener",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
115 "FileHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
116 "FTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
117 "HTTPBasicAuthHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
118 "HTTPDigestAuthHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
119 "HTTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
120 "HTTPPasswordMgrWithDefaultRealm",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
121 "HTTPSHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
122 "install_opener",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
123 "ProxyHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
124 "Request",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
125 "urlopen",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
126 ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
127 urlerr._registeraliases(urllib2, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
128 "HTTPError",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
129 "URLError",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
130 ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
131 httpserver._registeraliases(BaseHTTPServer, (
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
132 "HTTPServer",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
133 "BaseHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
134 ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
135 httpserver._registeraliases(SimpleHTTPServer, (
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
136 "SimpleHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
137 ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
138 httpserver._registeraliases(CGIHTTPServer, (
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
139 "CGIHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
140 ))
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
141
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
142 else:
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
143 import urllib.request
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
144 urlreq._registeraliases(urllib.request, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
145 "AbstractHTTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
146 "addclosehook",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
147 "addinfourl",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
148 "BaseHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
149 "build_opener",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
150 "FileHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
151 "FTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
152 "ftpwrapper",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
153 "HTTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
154 "HTTPSHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
155 "install_opener",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
156 "pathname2url",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
157 "HTTPBasicAuthHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
158 "HTTPDigestAuthHandler",
29414
2646fbba4ca7 pycompat: add HTTPPasswordMgrWithDefaultRealm to Python 3 block
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29405
diff changeset
159 "HTTPPasswordMgrWithDefaultRealm",
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
160 "ProxyHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
161 "quote",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
162 "Request",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
163 "splitattr",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
164 "splitpasswd",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
165 "splitport",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
166 "splituser",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
167 "unquote",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
168 "url2pathname",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
169 "urlopen",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
170 ))
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
171 import urllib.error
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
172 urlerr._registeraliases(urllib.error, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
173 "HTTPError",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
174 "URLError",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
175 ))
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
176 import http.server
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
177 httpserver._registeraliases(http.server, (
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
178 "HTTPServer",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
179 "BaseHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
180 "SimpleHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
181 "CGIHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
182 ))