##// END OF EJS Templates
pycompat: add HTTPPasswordMgrWithDefaultRealm to Python 3 block...
Gregory Szorc -
r29414:2646fbba default
parent child Browse files
Show More
@@ -1,130 +1,131
1 # pycompat.py - portability shim for python 3
1 # pycompat.py - portability shim for python 3
2 #
2 #
3 # This software may be used and distributed according to the terms of the
3 # This software may be used and distributed according to the terms of the
4 # GNU General Public License version 2 or any later version.
4 # GNU General Public License version 2 or any later version.
5
5
6 """Mercurial portability shim for python 3.
6 """Mercurial portability shim for python 3.
7
7
8 This contains aliases to hide python version-specific details from the core.
8 This contains aliases to hide python version-specific details from the core.
9 """
9 """
10
10
11 from __future__ import absolute_import
11 from __future__ import absolute_import
12
12
13 try:
13 try:
14 import cPickle as pickle
14 import cPickle as pickle
15 pickle.dumps
15 pickle.dumps
16 except ImportError:
16 except ImportError:
17 import pickle
17 import pickle
18 pickle.dumps # silence pyflakes
18 pickle.dumps # silence pyflakes
19
19
20 try:
20 try:
21 import cStringIO as io
21 import cStringIO as io
22 stringio = io.StringIO
22 stringio = io.StringIO
23 except ImportError:
23 except ImportError:
24 import io
24 import io
25 stringio = io.StringIO
25 stringio = io.StringIO
26
26
27 try:
27 try:
28 import Queue as _queue
28 import Queue as _queue
29 _queue.Queue
29 _queue.Queue
30 except ImportError:
30 except ImportError:
31 import queue as _queue
31 import queue as _queue
32 empty = _queue.Empty
32 empty = _queue.Empty
33 queue = _queue.Queue
33 queue = _queue.Queue
34
34
35 class _pycompatstub(object):
35 class _pycompatstub(object):
36 pass
36 pass
37
37
38 def _alias(alias, origin, items):
38 def _alias(alias, origin, items):
39 """ populate a _pycompatstub
39 """ populate a _pycompatstub
40
40
41 copies items from origin to alias
41 copies items from origin to alias
42 """
42 """
43 def hgcase(item):
43 def hgcase(item):
44 return item.replace('_', '').lower()
44 return item.replace('_', '').lower()
45 for item in items:
45 for item in items:
46 try:
46 try:
47 setattr(alias, hgcase(item), getattr(origin, item))
47 setattr(alias, hgcase(item), getattr(origin, item))
48 except AttributeError:
48 except AttributeError:
49 pass
49 pass
50
50
51 urlreq = _pycompatstub()
51 urlreq = _pycompatstub()
52 urlerr = _pycompatstub()
52 urlerr = _pycompatstub()
53 try:
53 try:
54 import urllib2
54 import urllib2
55 import urllib
55 import urllib
56 _alias(urlreq, urllib, (
56 _alias(urlreq, urllib, (
57 "addclosehook",
57 "addclosehook",
58 "addinfourl",
58 "addinfourl",
59 "ftpwrapper",
59 "ftpwrapper",
60 "pathname2url",
60 "pathname2url",
61 "quote",
61 "quote",
62 "splitattr",
62 "splitattr",
63 "splitpasswd",
63 "splitpasswd",
64 "splitport",
64 "splitport",
65 "splituser",
65 "splituser",
66 "unquote",
66 "unquote",
67 "url2pathname",
67 "url2pathname",
68 "urlencode",
68 "urlencode",
69 "urlencode",
69 "urlencode",
70 ))
70 ))
71 _alias(urlreq, urllib2, (
71 _alias(urlreq, urllib2, (
72 "AbstractHTTPHandler",
72 "AbstractHTTPHandler",
73 "BaseHandler",
73 "BaseHandler",
74 "build_opener",
74 "build_opener",
75 "FileHandler",
75 "FileHandler",
76 "FTPHandler",
76 "FTPHandler",
77 "HTTPBasicAuthHandler",
77 "HTTPBasicAuthHandler",
78 "HTTPDigestAuthHandler",
78 "HTTPDigestAuthHandler",
79 "HTTPHandler",
79 "HTTPHandler",
80 "HTTPPasswordMgrWithDefaultRealm",
80 "HTTPPasswordMgrWithDefaultRealm",
81 "HTTPSHandler",
81 "HTTPSHandler",
82 "install_opener",
82 "install_opener",
83 "ProxyHandler",
83 "ProxyHandler",
84 "Request",
84 "Request",
85 "urlopen",
85 "urlopen",
86 ))
86 ))
87 _alias(urlerr, urllib2, (
87 _alias(urlerr, urllib2, (
88 "HTTPError",
88 "HTTPError",
89 "URLError",
89 "URLError",
90 ))
90 ))
91
91
92 except ImportError:
92 except ImportError:
93 import urllib.request
93 import urllib.request
94 _alias(urlreq, urllib.request, (
94 _alias(urlreq, urllib.request, (
95 "AbstractHTTPHandler",
95 "AbstractHTTPHandler",
96 "addclosehook",
96 "addclosehook",
97 "addinfourl",
97 "addinfourl",
98 "BaseHandler",
98 "BaseHandler",
99 "build_opener",
99 "build_opener",
100 "FileHandler",
100 "FileHandler",
101 "FTPHandler",
101 "FTPHandler",
102 "ftpwrapper",
102 "ftpwrapper",
103 "HTTPHandler",
103 "HTTPHandler",
104 "HTTPSHandler",
104 "HTTPSHandler",
105 "install_opener",
105 "install_opener",
106 "pathname2url",
106 "pathname2url",
107 "HTTPBasicAuthHandler",
107 "HTTPBasicAuthHandler",
108 "HTTPDigestAuthHandler",
108 "HTTPDigestAuthHandler",
109 "HTTPPasswordMgrWithDefaultRealm",
109 "ProxyHandler",
110 "ProxyHandler",
110 "quote",
111 "quote",
111 "Request",
112 "Request",
112 "splitattr",
113 "splitattr",
113 "splitpasswd",
114 "splitpasswd",
114 "splitport",
115 "splitport",
115 "splituser",
116 "splituser",
116 "unquote",
117 "unquote",
117 "url2pathname",
118 "url2pathname",
118 "urlopen",
119 "urlopen",
119 ))
120 ))
120 import urllib.error
121 import urllib.error
121 _alias(urlerr, urllib.error, (
122 _alias(urlerr, urllib.error, (
122 "HTTPError",
123 "HTTPError",
123 "URLError",
124 "URLError",
124 ))
125 ))
125
126
126 try:
127 try:
127 xrange
128 xrange
128 except NameError:
129 except NameError:
129 import builtins
130 import builtins
130 builtins.xrange = range
131 builtins.xrange = range
General Comments 0
You need to be logged in to leave comments. Login now