##// END OF EJS Templates
pycompat: remove multiple occurences of urlencode...
Pulkit Goyal -
r29778:594035c1 default
parent child Browse files
Show More
@@ -1,153 +1,152 b''
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 import sys
13 import sys
14
14
15 if sys.version_info[0] < 3:
15 if sys.version_info[0] < 3:
16 import cPickle as pickle
16 import cPickle as pickle
17 import cStringIO as io
17 import cStringIO as io
18 import httplib
18 import httplib
19 import Queue as _queue
19 import Queue as _queue
20 import SocketServer as socketserver
20 import SocketServer as socketserver
21 import urlparse
21 import urlparse
22 import xmlrpclib
22 import xmlrpclib
23 else:
23 else:
24 import http.client as httplib
24 import http.client as httplib
25 import io
25 import io
26 import pickle
26 import pickle
27 import queue as _queue
27 import queue as _queue
28 import socketserver
28 import socketserver
29 import urllib.parse as urlparse
29 import urllib.parse as urlparse
30 import xmlrpc.client as xmlrpclib
30 import xmlrpc.client as xmlrpclib
31
31
32 stringio = io.StringIO
32 stringio = io.StringIO
33 empty = _queue.Empty
33 empty = _queue.Empty
34 queue = _queue.Queue
34 queue = _queue.Queue
35
35
36 class _pycompatstub(object):
36 class _pycompatstub(object):
37 pass
37 pass
38
38
39 def _alias(alias, origin, items):
39 def _alias(alias, origin, items):
40 """ populate a _pycompatstub
40 """ populate a _pycompatstub
41
41
42 copies items from origin to alias
42 copies items from origin to alias
43 """
43 """
44 def hgcase(item):
44 def hgcase(item):
45 return item.replace('_', '').lower()
45 return item.replace('_', '').lower()
46 for item in items:
46 for item in items:
47 try:
47 try:
48 setattr(alias, hgcase(item), getattr(origin, item))
48 setattr(alias, hgcase(item), getattr(origin, item))
49 except AttributeError:
49 except AttributeError:
50 pass
50 pass
51
51
52 httpserver = _pycompatstub()
52 httpserver = _pycompatstub()
53 urlreq = _pycompatstub()
53 urlreq = _pycompatstub()
54 urlerr = _pycompatstub()
54 urlerr = _pycompatstub()
55 try:
55 try:
56 import BaseHTTPServer
56 import BaseHTTPServer
57 import CGIHTTPServer
57 import CGIHTTPServer
58 import SimpleHTTPServer
58 import SimpleHTTPServer
59 import urllib2
59 import urllib2
60 import urllib
60 import urllib
61 _alias(urlreq, urllib, (
61 _alias(urlreq, urllib, (
62 "addclosehook",
62 "addclosehook",
63 "addinfourl",
63 "addinfourl",
64 "ftpwrapper",
64 "ftpwrapper",
65 "pathname2url",
65 "pathname2url",
66 "quote",
66 "quote",
67 "splitattr",
67 "splitattr",
68 "splitpasswd",
68 "splitpasswd",
69 "splitport",
69 "splitport",
70 "splituser",
70 "splituser",
71 "unquote",
71 "unquote",
72 "url2pathname",
72 "url2pathname",
73 "urlencode",
73 "urlencode",
74 "urlencode",
75 ))
74 ))
76 _alias(urlreq, urllib2, (
75 _alias(urlreq, urllib2, (
77 "AbstractHTTPHandler",
76 "AbstractHTTPHandler",
78 "BaseHandler",
77 "BaseHandler",
79 "build_opener",
78 "build_opener",
80 "FileHandler",
79 "FileHandler",
81 "FTPHandler",
80 "FTPHandler",
82 "HTTPBasicAuthHandler",
81 "HTTPBasicAuthHandler",
83 "HTTPDigestAuthHandler",
82 "HTTPDigestAuthHandler",
84 "HTTPHandler",
83 "HTTPHandler",
85 "HTTPPasswordMgrWithDefaultRealm",
84 "HTTPPasswordMgrWithDefaultRealm",
86 "HTTPSHandler",
85 "HTTPSHandler",
87 "install_opener",
86 "install_opener",
88 "ProxyHandler",
87 "ProxyHandler",
89 "Request",
88 "Request",
90 "urlopen",
89 "urlopen",
91 ))
90 ))
92 _alias(urlerr, urllib2, (
91 _alias(urlerr, urllib2, (
93 "HTTPError",
92 "HTTPError",
94 "URLError",
93 "URLError",
95 ))
94 ))
96 _alias(httpserver, BaseHTTPServer, (
95 _alias(httpserver, BaseHTTPServer, (
97 "HTTPServer",
96 "HTTPServer",
98 "BaseHTTPRequestHandler",
97 "BaseHTTPRequestHandler",
99 ))
98 ))
100 _alias(httpserver, SimpleHTTPServer, (
99 _alias(httpserver, SimpleHTTPServer, (
101 "SimpleHTTPRequestHandler",
100 "SimpleHTTPRequestHandler",
102 ))
101 ))
103 _alias(httpserver, CGIHTTPServer, (
102 _alias(httpserver, CGIHTTPServer, (
104 "CGIHTTPRequestHandler",
103 "CGIHTTPRequestHandler",
105 ))
104 ))
106
105
107 except ImportError:
106 except ImportError:
108 import urllib.request
107 import urllib.request
109 _alias(urlreq, urllib.request, (
108 _alias(urlreq, urllib.request, (
110 "AbstractHTTPHandler",
109 "AbstractHTTPHandler",
111 "addclosehook",
110 "addclosehook",
112 "addinfourl",
111 "addinfourl",
113 "BaseHandler",
112 "BaseHandler",
114 "build_opener",
113 "build_opener",
115 "FileHandler",
114 "FileHandler",
116 "FTPHandler",
115 "FTPHandler",
117 "ftpwrapper",
116 "ftpwrapper",
118 "HTTPHandler",
117 "HTTPHandler",
119 "HTTPSHandler",
118 "HTTPSHandler",
120 "install_opener",
119 "install_opener",
121 "pathname2url",
120 "pathname2url",
122 "HTTPBasicAuthHandler",
121 "HTTPBasicAuthHandler",
123 "HTTPDigestAuthHandler",
122 "HTTPDigestAuthHandler",
124 "HTTPPasswordMgrWithDefaultRealm",
123 "HTTPPasswordMgrWithDefaultRealm",
125 "ProxyHandler",
124 "ProxyHandler",
126 "quote",
125 "quote",
127 "Request",
126 "Request",
128 "splitattr",
127 "splitattr",
129 "splitpasswd",
128 "splitpasswd",
130 "splitport",
129 "splitport",
131 "splituser",
130 "splituser",
132 "unquote",
131 "unquote",
133 "url2pathname",
132 "url2pathname",
134 "urlopen",
133 "urlopen",
135 ))
134 ))
136 import urllib.error
135 import urllib.error
137 _alias(urlerr, urllib.error, (
136 _alias(urlerr, urllib.error, (
138 "HTTPError",
137 "HTTPError",
139 "URLError",
138 "URLError",
140 ))
139 ))
141 import http.server
140 import http.server
142 _alias(httpserver, http.server, (
141 _alias(httpserver, http.server, (
143 "HTTPServer",
142 "HTTPServer",
144 "BaseHTTPRequestHandler",
143 "BaseHTTPRequestHandler",
145 "SimpleHTTPRequestHandler",
144 "SimpleHTTPRequestHandler",
146 "CGIHTTPRequestHandler",
145 "CGIHTTPRequestHandler",
147 ))
146 ))
148
147
149 try:
148 try:
150 xrange
149 xrange
151 except NameError:
150 except NameError:
152 import builtins
151 import builtins
153 builtins.xrange = range
152 builtins.xrange = range
General Comments 0
You need to be logged in to leave comments. Login now