Show More
@@ -1,180 +1,153 b'' | |||
|
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 | try: | |
|
13 | import sys | |
|
14 | ||
|
15 | if sys.version_info[0] < 3: | |
|
14 | 16 | import cPickle as pickle |
|
15 | pickle.dumps | |
|
16 | except ImportError: | |
|
17 | import pickle | |
|
18 | pickle.dumps # silence pyflakes | |
|
19 | ||
|
20 | try: | |
|
17 | import cStringIO as io | |
|
21 | 18 | import httplib |
|
22 | httplib.HTTPException | |
|
23 | except ImportError: | |
|
24 | import http.client as httplib | |
|
25 | httplib.HTTPException | |
|
26 | ||
|
27 | try: | |
|
19 | import Queue as _queue | |
|
28 | 20 | import SocketServer as socketserver |
|
29 | socketserver.ThreadingMixIn | |
|
30 | except ImportError: | |
|
31 | import socketserver | |
|
32 | socketserver.ThreadingMixIn | |
|
33 | ||
|
34 | try: | |
|
21 | import urlparse | |
|
35 | 22 | import xmlrpclib |
|
36 | xmlrpclib.Transport | |
|
37 | except ImportError: | |
|
23 | else: | |
|
24 | import http.client as httplib | |
|
25 | import io | |
|
26 | import pickle | |
|
27 | import queue as _queue | |
|
28 | import socketserver | |
|
29 | import urllib.parse as urlparse | |
|
38 | 30 | import xmlrpc.client as xmlrpclib |
|
39 | xmlrpclib.Transport | |
|
40 | ||
|
41 | try: | |
|
42 | import urlparse | |
|
43 | urlparse.urlparse | |
|
44 | except ImportError: | |
|
45 | import urllib.parse as urlparse | |
|
46 | urlparse.urlparse | |
|
47 | 31 | |
|
48 | try: | |
|
49 | import cStringIO as io | |
|
50 | stringio = io.StringIO | |
|
51 | except ImportError: | |
|
52 | import io | |
|
53 | stringio = io.StringIO | |
|
54 | ||
|
55 | try: | |
|
56 | import Queue as _queue | |
|
57 | _queue.Queue | |
|
58 | except ImportError: | |
|
59 | import queue as _queue | |
|
32 | stringio = io.StringIO | |
|
60 | 33 | empty = _queue.Empty |
|
61 | 34 | queue = _queue.Queue |
|
62 | 35 | |
|
63 | 36 | class _pycompatstub(object): |
|
64 | 37 | pass |
|
65 | 38 | |
|
66 | 39 | def _alias(alias, origin, items): |
|
67 | 40 | """ populate a _pycompatstub |
|
68 | 41 | |
|
69 | 42 | copies items from origin to alias |
|
70 | 43 | """ |
|
71 | 44 | def hgcase(item): |
|
72 | 45 | return item.replace('_', '').lower() |
|
73 | 46 | for item in items: |
|
74 | 47 | try: |
|
75 | 48 | setattr(alias, hgcase(item), getattr(origin, item)) |
|
76 | 49 | except AttributeError: |
|
77 | 50 | pass |
|
78 | 51 | |
|
79 | 52 | httpserver = _pycompatstub() |
|
80 | 53 | urlreq = _pycompatstub() |
|
81 | 54 | urlerr = _pycompatstub() |
|
82 | 55 | try: |
|
83 | 56 | import BaseHTTPServer |
|
84 | 57 | import CGIHTTPServer |
|
85 | 58 | import SimpleHTTPServer |
|
86 | 59 | import urllib2 |
|
87 | 60 | import urllib |
|
88 | 61 | _alias(urlreq, urllib, ( |
|
89 | 62 | "addclosehook", |
|
90 | 63 | "addinfourl", |
|
91 | 64 | "ftpwrapper", |
|
92 | 65 | "pathname2url", |
|
93 | 66 | "quote", |
|
94 | 67 | "splitattr", |
|
95 | 68 | "splitpasswd", |
|
96 | 69 | "splitport", |
|
97 | 70 | "splituser", |
|
98 | 71 | "unquote", |
|
99 | 72 | "url2pathname", |
|
100 | 73 | "urlencode", |
|
101 | 74 | "urlencode", |
|
102 | 75 | )) |
|
103 | 76 | _alias(urlreq, urllib2, ( |
|
104 | 77 | "AbstractHTTPHandler", |
|
105 | 78 | "BaseHandler", |
|
106 | 79 | "build_opener", |
|
107 | 80 | "FileHandler", |
|
108 | 81 | "FTPHandler", |
|
109 | 82 | "HTTPBasicAuthHandler", |
|
110 | 83 | "HTTPDigestAuthHandler", |
|
111 | 84 | "HTTPHandler", |
|
112 | 85 | "HTTPPasswordMgrWithDefaultRealm", |
|
113 | 86 | "HTTPSHandler", |
|
114 | 87 | "install_opener", |
|
115 | 88 | "ProxyHandler", |
|
116 | 89 | "Request", |
|
117 | 90 | "urlopen", |
|
118 | 91 | )) |
|
119 | 92 | _alias(urlerr, urllib2, ( |
|
120 | 93 | "HTTPError", |
|
121 | 94 | "URLError", |
|
122 | 95 | )) |
|
123 | 96 | _alias(httpserver, BaseHTTPServer, ( |
|
124 | 97 | "HTTPServer", |
|
125 | 98 | "BaseHTTPRequestHandler", |
|
126 | 99 | )) |
|
127 | 100 | _alias(httpserver, SimpleHTTPServer, ( |
|
128 | 101 | "SimpleHTTPRequestHandler", |
|
129 | 102 | )) |
|
130 | 103 | _alias(httpserver, CGIHTTPServer, ( |
|
131 | 104 | "CGIHTTPRequestHandler", |
|
132 | 105 | )) |
|
133 | 106 | |
|
134 | 107 | except ImportError: |
|
135 | 108 | import urllib.request |
|
136 | 109 | _alias(urlreq, urllib.request, ( |
|
137 | 110 | "AbstractHTTPHandler", |
|
138 | 111 | "addclosehook", |
|
139 | 112 | "addinfourl", |
|
140 | 113 | "BaseHandler", |
|
141 | 114 | "build_opener", |
|
142 | 115 | "FileHandler", |
|
143 | 116 | "FTPHandler", |
|
144 | 117 | "ftpwrapper", |
|
145 | 118 | "HTTPHandler", |
|
146 | 119 | "HTTPSHandler", |
|
147 | 120 | "install_opener", |
|
148 | 121 | "pathname2url", |
|
149 | 122 | "HTTPBasicAuthHandler", |
|
150 | 123 | "HTTPDigestAuthHandler", |
|
151 | 124 | "HTTPPasswordMgrWithDefaultRealm", |
|
152 | 125 | "ProxyHandler", |
|
153 | 126 | "quote", |
|
154 | 127 | "Request", |
|
155 | 128 | "splitattr", |
|
156 | 129 | "splitpasswd", |
|
157 | 130 | "splitport", |
|
158 | 131 | "splituser", |
|
159 | 132 | "unquote", |
|
160 | 133 | "url2pathname", |
|
161 | 134 | "urlopen", |
|
162 | 135 | )) |
|
163 | 136 | import urllib.error |
|
164 | 137 | _alias(urlerr, urllib.error, ( |
|
165 | 138 | "HTTPError", |
|
166 | 139 | "URLError", |
|
167 | 140 | )) |
|
168 | 141 | import http.server |
|
169 | 142 | _alias(httpserver, http.server, ( |
|
170 | 143 | "HTTPServer", |
|
171 | 144 | "BaseHTTPRequestHandler", |
|
172 | 145 | "SimpleHTTPRequestHandler", |
|
173 | 146 | "CGIHTTPRequestHandler", |
|
174 | 147 | )) |
|
175 | 148 | |
|
176 | 149 | try: |
|
177 | 150 | xrange |
|
178 | 151 | except NameError: |
|
179 | 152 | import builtins |
|
180 | 153 | builtins.xrange = range |
@@ -1,13 +1,15 b'' | |||
|
1 | 1 | #require test-repo pyflakes hg10 |
|
2 | 2 | |
|
3 | 3 | $ . "$TESTDIR/helpers-testrepo.sh" |
|
4 | 4 | $ cd "`dirname "$TESTDIR"`" |
|
5 | 5 | |
|
6 | 6 | run pyflakes on all tracked files ending in .py or without a file ending |
|
7 | 7 | (skipping binary file random-seed) |
|
8 | 8 | |
|
9 |
$ hg locate 'set:**.py or grep("^#!.*python")' |
|
|
9 | $ hg locate 'set:**.py or grep("^#!.*python")' \ | |
|
10 | > -X mercurial/pycompat.py \ | |
|
11 | > 2>/dev/null \ | |
|
10 | 12 | > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py" |
|
11 | 13 | tests/filterpyflakes.py:61: undefined name 'undefinedname' |
|
12 | 14 | |
|
13 | 15 |
General Comments 0
You need to be logged in to leave comments.
Login now