##// END OF EJS Templates
pyflakes: use pycompat.pickles to prevent error...
Pierre-Yves David -
r29405:fbe380dc default
parent child Browse files
Show More
@@ -1,129 +1,130
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
19
19 try:
20 try:
20 import cStringIO as io
21 import cStringIO as io
21 stringio = io.StringIO
22 stringio = io.StringIO
22 except ImportError:
23 except ImportError:
23 import io
24 import io
24 stringio = io.StringIO
25 stringio = io.StringIO
25
26
26 try:
27 try:
27 import Queue as _queue
28 import Queue as _queue
28 _queue.Queue
29 _queue.Queue
29 except ImportError:
30 except ImportError:
30 import queue as _queue
31 import queue as _queue
31 empty = _queue.Empty
32 empty = _queue.Empty
32 queue = _queue.Queue
33 queue = _queue.Queue
33
34
34 class _pycompatstub(object):
35 class _pycompatstub(object):
35 pass
36 pass
36
37
37 def _alias(alias, origin, items):
38 def _alias(alias, origin, items):
38 """ populate a _pycompatstub
39 """ populate a _pycompatstub
39
40
40 copies items from origin to alias
41 copies items from origin to alias
41 """
42 """
42 def hgcase(item):
43 def hgcase(item):
43 return item.replace('_', '').lower()
44 return item.replace('_', '').lower()
44 for item in items:
45 for item in items:
45 try:
46 try:
46 setattr(alias, hgcase(item), getattr(origin, item))
47 setattr(alias, hgcase(item), getattr(origin, item))
47 except AttributeError:
48 except AttributeError:
48 pass
49 pass
49
50
50 urlreq = _pycompatstub()
51 urlreq = _pycompatstub()
51 urlerr = _pycompatstub()
52 urlerr = _pycompatstub()
52 try:
53 try:
53 import urllib2
54 import urllib2
54 import urllib
55 import urllib
55 _alias(urlreq, urllib, (
56 _alias(urlreq, urllib, (
56 "addclosehook",
57 "addclosehook",
57 "addinfourl",
58 "addinfourl",
58 "ftpwrapper",
59 "ftpwrapper",
59 "pathname2url",
60 "pathname2url",
60 "quote",
61 "quote",
61 "splitattr",
62 "splitattr",
62 "splitpasswd",
63 "splitpasswd",
63 "splitport",
64 "splitport",
64 "splituser",
65 "splituser",
65 "unquote",
66 "unquote",
66 "url2pathname",
67 "url2pathname",
67 "urlencode",
68 "urlencode",
68 "urlencode",
69 "urlencode",
69 ))
70 ))
70 _alias(urlreq, urllib2, (
71 _alias(urlreq, urllib2, (
71 "AbstractHTTPHandler",
72 "AbstractHTTPHandler",
72 "BaseHandler",
73 "BaseHandler",
73 "build_opener",
74 "build_opener",
74 "FileHandler",
75 "FileHandler",
75 "FTPHandler",
76 "FTPHandler",
76 "HTTPBasicAuthHandler",
77 "HTTPBasicAuthHandler",
77 "HTTPDigestAuthHandler",
78 "HTTPDigestAuthHandler",
78 "HTTPHandler",
79 "HTTPHandler",
79 "HTTPPasswordMgrWithDefaultRealm",
80 "HTTPPasswordMgrWithDefaultRealm",
80 "HTTPSHandler",
81 "HTTPSHandler",
81 "install_opener",
82 "install_opener",
82 "ProxyHandler",
83 "ProxyHandler",
83 "Request",
84 "Request",
84 "urlopen",
85 "urlopen",
85 ))
86 ))
86 _alias(urlerr, urllib2, (
87 _alias(urlerr, urllib2, (
87 "HTTPError",
88 "HTTPError",
88 "URLError",
89 "URLError",
89 ))
90 ))
90
91
91 except ImportError:
92 except ImportError:
92 import urllib.request
93 import urllib.request
93 _alias(urlreq, urllib.request, (
94 _alias(urlreq, urllib.request, (
94 "AbstractHTTPHandler",
95 "AbstractHTTPHandler",
95 "addclosehook",
96 "addclosehook",
96 "addinfourl",
97 "addinfourl",
97 "BaseHandler",
98 "BaseHandler",
98 "build_opener",
99 "build_opener",
99 "FileHandler",
100 "FileHandler",
100 "FTPHandler",
101 "FTPHandler",
101 "ftpwrapper",
102 "ftpwrapper",
102 "HTTPHandler",
103 "HTTPHandler",
103 "HTTPSHandler",
104 "HTTPSHandler",
104 "install_opener",
105 "install_opener",
105 "pathname2url",
106 "pathname2url",
106 "HTTPBasicAuthHandler",
107 "HTTPBasicAuthHandler",
107 "HTTPDigestAuthHandler",
108 "HTTPDigestAuthHandler",
108 "ProxyHandler",
109 "ProxyHandler",
109 "quote",
110 "quote",
110 "Request",
111 "Request",
111 "splitattr",
112 "splitattr",
112 "splitpasswd",
113 "splitpasswd",
113 "splitport",
114 "splitport",
114 "splituser",
115 "splituser",
115 "unquote",
116 "unquote",
116 "url2pathname",
117 "url2pathname",
117 "urlopen",
118 "urlopen",
118 ))
119 ))
119 import urllib.error
120 import urllib.error
120 _alias(urlerr, urllib.error, (
121 _alias(urlerr, urllib.error, (
121 "HTTPError",
122 "HTTPError",
122 "URLError",
123 "URLError",
123 ))
124 ))
124
125
125 try:
126 try:
126 xrange
127 xrange
127 except NameError:
128 except NameError:
128 import builtins
129 import builtins
129 builtins.xrange = range
130 builtins.xrange = range
General Comments 0
You need to be logged in to leave comments. Login now