author | Martijn Pieters <mjpieters@fb.com> |
Sun, 09 Oct 2016 17:44:23 +0200 | |
changeset 30119 | f4a5e0e86a7e |
parent 30086 | f3a1089654e3 |
child 30133 | f6dcda7505f9 |
permissions | -rw-r--r-- |
28818
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
1 |
# pycompat.py - portability shim for python 3 |
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
2 |
# |
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
3 |
# This software may be used and distributed according to the terms of the |
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
4 |
# GNU General Public License version 2 or any later version. |
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
5 |
|
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
6 |
"""Mercurial portability shim for python 3. |
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
7 |
|
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
8 |
This contains aliases to hide python version-specific details from the core. |
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
9 |
""" |
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
10 |
|
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
11 |
from __future__ import absolute_import |
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
12 |
|
29584
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
13 |
import sys |
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
14 |
|
30030
0f6d6fdd3c2a
pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents:
29801
diff
changeset
|
15 |
ispy3 = (sys.version_info[0] >= 3) |
0f6d6fdd3c2a
pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents:
29801
diff
changeset
|
16 |
|
0f6d6fdd3c2a
pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents:
29801
diff
changeset
|
17 |
if not ispy3: |
29324
b501579147f1
py3: conditionalize cPickle import by adding in util
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28882
diff
changeset
|
18 |
import cPickle as pickle |
29584
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
19 |
import cStringIO as io |
29455
0c741fd6158a
py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29433
diff
changeset
|
20 |
import httplib |
29584
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
21 |
import Queue as _queue |
29433
33770d2b6cf9
py3: conditionalize SocketServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29432
diff
changeset
|
22 |
import SocketServer as socketserver |
29584
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
23 |
import urlparse |
29432
34b914ac573e
py3: conditionalize xmlrpclib import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29431
diff
changeset
|
24 |
import xmlrpclib |
29584
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
25 |
else: |
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
26 |
import http.client as httplib |
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
27 |
import io |
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
28 |
import pickle |
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
29 |
import queue as _queue |
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
30 |
import socketserver |
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
31 |
import urllib.parse as urlparse |
29432
34b914ac573e
py3: conditionalize xmlrpclib import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29431
diff
changeset
|
32 |
import xmlrpc.client as xmlrpclib |
29431
80880ad3fccd
py3: conditionalize the urlparse import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29414
diff
changeset
|
33 |
|
30030
0f6d6fdd3c2a
pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents:
29801
diff
changeset
|
34 |
if ispy3: |
29797
965c91bad9e3
py3: move xrange alias next to import lines
Yuya Nishihara <yuya@tcha.org>
parents:
29779
diff
changeset
|
35 |
import builtins |
29799
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
36 |
import functools |
30119
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
37 |
import os |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
38 |
fsencode = os.fsencode |
29797
965c91bad9e3
py3: move xrange alias next to import lines
Yuya Nishihara <yuya@tcha.org>
parents:
29779
diff
changeset
|
39 |
|
30032
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
40 |
def sysstr(s): |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
41 |
"""Return a keyword str to be passed to Python functions such as |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
42 |
getattr() and str.encode() |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
43 |
|
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
44 |
This never raises UnicodeDecodeError. Non-ascii characters are |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
45 |
considered invalid and mapped to arbitrary but unique code points |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
46 |
such that 'sysstr(a) != sysstr(b)' for all 'a != b'. |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
47 |
""" |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
48 |
if isinstance(s, builtins.str): |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
49 |
return s |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
50 |
return s.decode(u'latin-1') |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
51 |
|
29799
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
52 |
def _wrapattrfunc(f): |
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
53 |
@functools.wraps(f) |
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
54 |
def w(object, name, *args): |
30032
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
55 |
return f(object, sysstr(name), *args) |
29799
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
56 |
return w |
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
57 |
|
29800
178c89e8519a
py3: import builtin wrappers automagically by code transformer
Yuya Nishihara <yuya@tcha.org>
parents:
29799
diff
changeset
|
58 |
# these wrappers are automagically imported by hgloader |
29799
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
59 |
delattr = _wrapattrfunc(builtins.delattr) |
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
60 |
getattr = _wrapattrfunc(builtins.getattr) |
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
61 |
hasattr = _wrapattrfunc(builtins.hasattr) |
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
62 |
setattr = _wrapattrfunc(builtins.setattr) |
29800
178c89e8519a
py3: import builtin wrappers automagically by code transformer
Yuya Nishihara <yuya@tcha.org>
parents:
29799
diff
changeset
|
63 |
xrange = builtins.range |
29799
45fa8de47a0f
py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents:
29798
diff
changeset
|
64 |
|
30032
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
65 |
else: |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
66 |
def sysstr(s): |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
67 |
return s |
2219f4f82ede
pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents:
30030
diff
changeset
|
68 |
|
30119
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
69 |
# Partial backport from os.py in Python 3 |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
70 |
def _fscodec(): |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
71 |
encoding = sys.getfilesystemencoding() |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
72 |
if encoding == 'mbcs': |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
73 |
errors = 'strict' |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
74 |
else: |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
75 |
errors = 'surrogateescape' |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
76 |
|
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
77 |
def fsencode(filename): |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
78 |
""" |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
79 |
Encode filename to the filesystem encoding with 'surrogateescape' |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
80 |
error handler, return bytes unchanged. On Windows, use 'strict' |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
81 |
error handler if the file system encoding is 'mbcs' (which is the |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
82 |
default encoding). |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
83 |
""" |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
84 |
if isinstance(filename, str): |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
85 |
return filename |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
86 |
elif isinstance(filename, unicode): |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
87 |
return filename.encode(encoding, errors) |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
88 |
else: |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
89 |
raise TypeError( |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
90 |
"expect str or unicode, not %s" % type(filename).__name__) |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
91 |
|
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
92 |
return fsencode |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
93 |
|
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
94 |
fsencode = _fscodec() |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
95 |
del _fscodec |
f4a5e0e86a7e
py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents:
30086
diff
changeset
|
96 |
|
29584
06587edd1233
pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29566
diff
changeset
|
97 |
stringio = io.StringIO |
28818
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
98 |
empty = _queue.Empty |
6041fb8f2da8
pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff
changeset
|
99 |
queue = _queue.Queue |
28834
2fac032c1269
pycompat: alias xrange to range in py3
timeless <timeless@mozdev.org>
parents:
28833
diff
changeset
|
100 |
|
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
101 |
class _pycompatstub(object): |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
102 |
def __init__(self): |
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
103 |
self._aliases = {} |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
104 |
|
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
105 |
def _registeraliases(self, origin, items): |
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
106 |
"""Add items that will be populated at the first access""" |
30086
f3a1089654e3
pycompat: when setting attrs, ensure we use sysstr
Augie Fackler <augie@google.com>
parents:
30032
diff
changeset
|
107 |
items = map(sysstr, items) |
f3a1089654e3
pycompat: when setting attrs, ensure we use sysstr
Augie Fackler <augie@google.com>
parents:
30032
diff
changeset
|
108 |
self._aliases.update( |
f3a1089654e3
pycompat: when setting attrs, ensure we use sysstr
Augie Fackler <augie@google.com>
parents:
30032
diff
changeset
|
109 |
(item.replace(sysstr('_'), sysstr('')).lower(), (origin, item)) |
f3a1089654e3
pycompat: when setting attrs, ensure we use sysstr
Augie Fackler <augie@google.com>
parents:
30032
diff
changeset
|
110 |
for item in items) |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
111 |
|
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
112 |
def __getattr__(self, name): |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
113 |
try: |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
114 |
origin, item = self._aliases[name] |
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
115 |
except KeyError: |
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
116 |
raise AttributeError(name) |
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
117 |
self.__dict__[name] = obj = getattr(origin, item) |
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
118 |
return obj |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
119 |
|
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
120 |
httpserver = _pycompatstub() |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
121 |
urlreq = _pycompatstub() |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
122 |
urlerr = _pycompatstub() |
30030
0f6d6fdd3c2a
pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents:
29801
diff
changeset
|
123 |
if not ispy3: |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
124 |
import BaseHTTPServer |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
125 |
import CGIHTTPServer |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
126 |
import SimpleHTTPServer |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
127 |
import urllib2 |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
128 |
import urllib |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
129 |
urlreq._registeraliases(urllib, ( |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
130 |
"addclosehook", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
131 |
"addinfourl", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
132 |
"ftpwrapper", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
133 |
"pathname2url", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
134 |
"quote", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
135 |
"splitattr", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
136 |
"splitpasswd", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
137 |
"splitport", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
138 |
"splituser", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
139 |
"unquote", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
140 |
"url2pathname", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
141 |
"urlencode", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
142 |
)) |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
143 |
urlreq._registeraliases(urllib2, ( |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
144 |
"AbstractHTTPHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
145 |
"BaseHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
146 |
"build_opener", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
147 |
"FileHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
148 |
"FTPHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
149 |
"HTTPBasicAuthHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
150 |
"HTTPDigestAuthHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
151 |
"HTTPHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
152 |
"HTTPPasswordMgrWithDefaultRealm", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
153 |
"HTTPSHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
154 |
"install_opener", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
155 |
"ProxyHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
156 |
"Request", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
157 |
"urlopen", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
158 |
)) |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
159 |
urlerr._registeraliases(urllib2, ( |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
160 |
"HTTPError", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
161 |
"URLError", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
162 |
)) |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
163 |
httpserver._registeraliases(BaseHTTPServer, ( |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
164 |
"HTTPServer", |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
165 |
"BaseHTTPRequestHandler", |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
166 |
)) |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
167 |
httpserver._registeraliases(SimpleHTTPServer, ( |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
168 |
"SimpleHTTPRequestHandler", |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
169 |
)) |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
170 |
httpserver._registeraliases(CGIHTTPServer, ( |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
171 |
"CGIHTTPRequestHandler", |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
172 |
)) |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
173 |
|
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
174 |
else: |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
175 |
import urllib.request |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
176 |
urlreq._registeraliases(urllib.request, ( |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
177 |
"AbstractHTTPHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
178 |
"addclosehook", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
179 |
"addinfourl", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
180 |
"BaseHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
181 |
"build_opener", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
182 |
"FileHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
183 |
"FTPHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
184 |
"ftpwrapper", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
185 |
"HTTPHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
186 |
"HTTPSHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
187 |
"install_opener", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
188 |
"pathname2url", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
189 |
"HTTPBasicAuthHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
190 |
"HTTPDigestAuthHandler", |
29414
2646fbba4ca7
pycompat: add HTTPPasswordMgrWithDefaultRealm to Python 3 block
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29405
diff
changeset
|
191 |
"HTTPPasswordMgrWithDefaultRealm", |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
192 |
"ProxyHandler", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
193 |
"quote", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
194 |
"Request", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
195 |
"splitattr", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
196 |
"splitpasswd", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
197 |
"splitport", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
198 |
"splituser", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
199 |
"unquote", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
200 |
"url2pathname", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
201 |
"urlopen", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
202 |
)) |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
203 |
import urllib.error |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
204 |
urlerr._registeraliases(urllib.error, ( |
28882
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
205 |
"HTTPError", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
206 |
"URLError", |
800ec7c048b0
pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents:
28835
diff
changeset
|
207 |
)) |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
208 |
import http.server |
29801
c63ab0524db7
pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents:
29800
diff
changeset
|
209 |
httpserver._registeraliases(http.server, ( |
29566
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
210 |
"HTTPServer", |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
211 |
"BaseHTTPRequestHandler", |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
212 |
"SimpleHTTPRequestHandler", |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
213 |
"CGIHTTPRequestHandler", |
075146e85bb6
py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29455
diff
changeset
|
214 |
)) |