Commit Graph

21 Commits

Author SHA1 Message Date
Yuya Nishihara
69789d265a pycompat: delay loading modules registered to stub
Replacement _pycompatstub designed to be compatible with our demandimporter.
try-except is replaced by version comparison because ImportError will no longer
be raised immediately.
2016-08-14 14:46:24 +09:00
Yuya Nishihara
12eca1889e py3: import builtin wrappers automagically by code transformer
This should be less invasive than mucking builtins.

Since tokenize.untokenize() looks start/end positions of tokens, we calculates
them from the NEWLINE token of the future import.
2016-08-16 12:35:15 +09:00
Yuya Nishihara
29c5e8dc21 py3: provide (del|get|has|set)attr wrappers that accepts bytes
These functions will be imported automagically by our code transformer.

getattr() and setattr() are widely used in our code. We wouldn't probably
want to rewrite every single call of getattr/setattr. delattr() and hasattr()
aren't that important, but they are functions of the same kind.
2016-08-14 12:51:21 +09:00
Yuya Nishihara
df4c2c74a3 py3: check python version to enable builtins hack
Future patches will add (del|get|has|set)attr wrappers.
2016-08-14 12:44:13 +09:00
Yuya Nishihara
1532480b48 py3: move xrange alias next to import lines
Builtin functions should be available in compatibility code.
2016-08-14 12:41:54 +09:00
Pulkit Goyal
0ce0d571e7 pycompat: avoid using an extra function
We have a single line function which just lowercase the letters and replaces
"_" with "". Its better to avoid that function call. Moreover we calling this
 function around 33 times.
2016-08-13 04:21:42 +05:30
Pulkit Goyal
1eb9840e42 pycompat: remove multiple occurences of urlencode
By mistake we had two occurences of urlencode.
2016-08-13 03:03:01 +05:30
Pulkit Goyal
c87a2b01ec pycompat: make pycompat demandimport friendly
pycompat.py includes hack to import modules whose names are changed in Python 3.
We use try-except to load module according to the version of python. But this
method forces us to import the modules to raise an ImportError and hence making
it demandimport unfriendly.

This patch changes the try-except blocks to a single if-else block. To avoid
test-check-pyflakes.t complain about unused imports, pycompat.py is excluded
from the test.
2016-07-17 19:48:04 +05:30
Pulkit Goyal
6b3bc52b40 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
The BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer has been merged into
http.server in python 3. All of them has been merged as util.httpserver to use
in both python 2 and 3. This patch adds a regex to check-code to warn against
the use of BaseHTTPServer. Moreover this patch also includes updates to lower
part of test-check-py3-compat.t which used to remain unchanged.
2016-07-13 23:38:29 +05:30
Pulkit Goyal
af9d7f66d0 py3: conditionalize httplib import
The httplib library is renamed to http.client in python 3. So the
import is conditionalized and a test is added in check-code to warn
to use util.httplib
2016-06-28 16:01:53 +05:30
Pulkit Goyal
38a359ce5c py3: conditionalize SocketServer import
The SocketServer is renamed to socketserver in python 3
2016-06-27 16:48:54 +05:30
Pulkit Goyal
fdc0861e35 py3: conditionalize xmlrpclib import
The xmlrpclib library is renamed to xmlrpc.client in python 3
2016-06-27 16:37:37 +05:30
Pulkit Goyal
5fcc6a2628 py3: conditionalize the urlparse import
The urlparse library is renamed to urllib.parse in python 3
2016-06-27 16:16:10 +05:30
Gregory Szorc
54aabad0ba pycompat: add HTTPPasswordMgrWithDefaultRealm to Python 3 block
Looks like we missed this in 46280bc1ec69.
2016-06-25 17:22:06 -07:00
Pierre-Yves David
c915441bc6 pyflakes: use pycompat.pickles to prevent error
The pyflakes in my test box complain about pickle in pycompat.

  mercurial/pycompat.py:17: 'pickle' imported but unused
2016-06-24 02:04:43 +02:00
Pulkit Goyal
5f52c722cf py3: conditionalize cPickle import by adding in util
The cPickle is renamed to _pickle in python3 and this C extension is available
 in pickle which was not included in earlier versions. So imports are conditionalized
 to import cPickle in py2 and pickle in py3. Moreover the use of pickle in py2 is
 switched to cPickle as the C extension is faster. The hack is added in util.py and
the modules import util.pickle
2016-06-04 14:38:00 +05:30
timeless
7816ecf261 pycompat: add util.urlerr util.urlreq classes for py3 compat
python3 url.request and url.error are mapped as util.urlreq/util.urlerr
python2 equivalents from urllib/urllib2 are mapped according to the py3
hierarchy
2016-04-07 00:05:48 +00:00
timeless
26ef04b4e1 pycompat: add util.stringio to handle py3 divergence
util.stringio = cStringIO.StringIO / io.StringIO
2016-04-06 20:31:31 +00:00
timeless
10677b7ace pycompat: alias xrange to range in py3 2016-04-06 22:35:52 +00:00
timeless
29cb0c1fb2 pycompat: fix demand import handling of Queue
When demandimport is enabled, simply importing a non existent module does
not trigger ImportError, a property access is necessary.
2016-04-08 14:03:05 +00:00
timeless
9bbc2a69f1 pycompat: add empty and queue to handle py3 divergence
While the pycompat module will actually handle divergence, please
access these properties from the util module:
util.queue = Queue.Queue / queue.Queue
util.empty = Queue.Empty / queue.Empty
2016-04-06 20:00:49 +00:00