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