mercurial/pycompat.py
author Pulkit Goyal <7895pulkit@gmail.com>
Sun, 18 Dec 2016 00:44:21 +0530
changeset 30623 c6026c20a3ce
parent 30579 fbc3f73dc802
child 30624 a82a6eee2613
permissions -rw-r--r--
py3: have a bytes version of os.altsep os.altsep returns unicodes on Python 3. We need a bytes version hence added pycompat.altsep.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
30578
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
    13
import getopt
30302
3874ddba1ab4 py3: add a bytes version of os.name
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30300
diff changeset
    14
import os
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    15
import sys
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    16
30031
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
    17
ispy3 = (sys.version_info[0] >= 3)
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
    18
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
    19
if not ispy3:
29324
b501579147f1 py3: conditionalize cPickle import by adding in util
Pulkit Goyal <7895pulkit@gmail.com>
parents: 28882
diff changeset
    20
    import cPickle as pickle
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    21
    import cStringIO as io
29455
0c741fd6158a py3: conditionalize httplib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29433
diff changeset
    22
    import httplib
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    23
    import Queue as _queue
29433
33770d2b6cf9 py3: conditionalize SocketServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29432
diff changeset
    24
    import SocketServer as socketserver
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    25
    import urlparse
30327
e0d9b6aab4c5 pycompat: introduce an alias for urllib.unquote
Augie Fackler <augie@google.com>
parents: 30303
diff changeset
    26
    urlunquote = urlparse.unquote
29432
34b914ac573e py3: conditionalize xmlrpclib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29431
diff changeset
    27
    import xmlrpclib
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    28
else:
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    29
    import http.client as httplib
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    30
    import io
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    31
    import pickle
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    32
    import queue as _queue
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    33
    import socketserver
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
    34
    import urllib.parse as urlparse
30327
e0d9b6aab4c5 pycompat: introduce an alias for urllib.unquote
Augie Fackler <augie@google.com>
parents: 30303
diff changeset
    35
    urlunquote = urlparse.unquote_to_bytes
29432
34b914ac573e py3: conditionalize xmlrpclib import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29431
diff changeset
    36
    import xmlrpc.client as xmlrpclib
29431
80880ad3fccd py3: conditionalize the urlparse import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29414
diff changeset
    37
30031
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
    38
if ispy3:
29797
965c91bad9e3 py3: move xrange alias next to import lines
Yuya Nishihara <yuya@tcha.org>
parents: 29779
diff changeset
    39
    import builtins
29799
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
    40
    import functools
30119
f4a5e0e86a7e py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents: 30086
diff changeset
    41
    fsencode = os.fsencode
30300
42af0590f4b9 py3: add os.fsdecode() as pycompat.fsdecode()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30133
diff changeset
    42
    fsdecode = os.fsdecode
30302
3874ddba1ab4 py3: add a bytes version of os.name
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30300
diff changeset
    43
    # A bytes version of os.name.
3874ddba1ab4 py3: add a bytes version of os.name
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30300
diff changeset
    44
    osname = os.name.encode('ascii')
30303
ad40d307a9f0 py3: have pycompat.ospathsep and pycompat.ossep
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30302
diff changeset
    45
    ospathsep = os.pathsep.encode('ascii')
ad40d307a9f0 py3: have pycompat.ospathsep and pycompat.ossep
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30302
diff changeset
    46
    ossep = os.sep.encode('ascii')
30623
c6026c20a3ce py3: have a bytes version of os.altsep
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30579
diff changeset
    47
    osaltsep = os.altsep
c6026c20a3ce py3: have a bytes version of os.altsep
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30579
diff changeset
    48
    if osaltsep:
c6026c20a3ce py3: have a bytes version of os.altsep
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30579
diff changeset
    49
        osaltsep = osaltsep.encode('ascii')
30500
fc0cfe6c87d7 py3: add os.getcwdb() to have bytes path
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30472
diff changeset
    50
    # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which
fc0cfe6c87d7 py3: add os.getcwdb() to have bytes path
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30472
diff changeset
    51
    # returns bytes.
fc0cfe6c87d7 py3: add os.getcwdb() to have bytes path
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30472
diff changeset
    52
    getcwd = os.getcwdb
30334
19d8e19fde5b py3: document why os.fsencode() can be used to get back bytes argv
Yuya Nishihara <yuya@tcha.org>
parents: 30330
diff changeset
    53
30472
277f4fe6d01a py3: provide bytes stdin/out/err through util module
Yuya Nishihara <yuya@tcha.org>
parents: 30334
diff changeset
    54
    # TODO: .buffer might not exist if std streams were replaced; we'll need
277f4fe6d01a py3: provide bytes stdin/out/err through util module
Yuya Nishihara <yuya@tcha.org>
parents: 30334
diff changeset
    55
    # a silly wrapper to make a bytes stream backed by a unicode one.
277f4fe6d01a py3: provide bytes stdin/out/err through util module
Yuya Nishihara <yuya@tcha.org>
parents: 30334
diff changeset
    56
    stdin = sys.stdin.buffer
277f4fe6d01a py3: provide bytes stdin/out/err through util module
Yuya Nishihara <yuya@tcha.org>
parents: 30334
diff changeset
    57
    stdout = sys.stdout.buffer
277f4fe6d01a py3: provide bytes stdin/out/err through util module
Yuya Nishihara <yuya@tcha.org>
parents: 30334
diff changeset
    58
    stderr = sys.stderr.buffer
277f4fe6d01a py3: provide bytes stdin/out/err through util module
Yuya Nishihara <yuya@tcha.org>
parents: 30334
diff changeset
    59
30334
19d8e19fde5b py3: document why os.fsencode() can be used to get back bytes argv
Yuya Nishihara <yuya@tcha.org>
parents: 30330
diff changeset
    60
    # Since Python 3 converts argv to wchar_t type by Py_DecodeLocale() on Unix,
19d8e19fde5b py3: document why os.fsencode() can be used to get back bytes argv
Yuya Nishihara <yuya@tcha.org>
parents: 30330
diff changeset
    61
    # we can use os.fsencode() to get back bytes argv.
19d8e19fde5b py3: document why os.fsencode() can be used to get back bytes argv
Yuya Nishihara <yuya@tcha.org>
parents: 30330
diff changeset
    62
    #
19d8e19fde5b py3: document why os.fsencode() can be used to get back bytes argv
Yuya Nishihara <yuya@tcha.org>
parents: 30330
diff changeset
    63
    # https://hg.python.org/cpython/file/v3.5.1/Programs/python.c#l55
19d8e19fde5b py3: document why os.fsencode() can be used to get back bytes argv
Yuya Nishihara <yuya@tcha.org>
parents: 30330
diff changeset
    64
    #
19d8e19fde5b py3: document why os.fsencode() can be used to get back bytes argv
Yuya Nishihara <yuya@tcha.org>
parents: 30330
diff changeset
    65
    # TODO: On Windows, the native argv is wchar_t, so we'll need a different
19d8e19fde5b py3: document why os.fsencode() can be used to get back bytes argv
Yuya Nishihara <yuya@tcha.org>
parents: 30330
diff changeset
    66
    # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior.
30330
a2f2f694dce9 py3: have bytes version of sys.argv
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30327
diff changeset
    67
    sysargv = list(map(os.fsencode, sys.argv))
29797
965c91bad9e3 py3: move xrange alias next to import lines
Yuya Nishihara <yuya@tcha.org>
parents: 29779
diff changeset
    68
30032
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
    69
    def sysstr(s):
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
    70
        """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: 30031
diff changeset
    71
        getattr() and str.encode()
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
    72
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
    73
        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: 30031
diff changeset
    74
        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: 30031
diff changeset
    75
        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: 30031
diff changeset
    76
        """
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
    77
        if isinstance(s, builtins.str):
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
    78
            return s
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
    79
        return s.decode(u'latin-1')
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
    80
29799
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
    81
    def _wrapattrfunc(f):
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
    82
        @functools.wraps(f)
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
    83
        def w(object, name, *args):
30032
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
    84
            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
    85
        return w
45fa8de47a0f py3: provide (del|get|has|set)attr wrappers that accepts bytes
Yuya Nishihara <yuya@tcha.org>
parents: 29798
diff changeset
    86
29800
178c89e8519a py3: import builtin wrappers automagically by code transformer
Yuya Nishihara <yuya@tcha.org>
parents: 29799
diff changeset
    87
    # 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
    88
    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
    89
    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
    90
    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
    91
    setattr = _wrapattrfunc(builtins.setattr)
29800
178c89e8519a py3: import builtin wrappers automagically by code transformer
Yuya Nishihara <yuya@tcha.org>
parents: 29799
diff changeset
    92
    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
    93
30578
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
    94
    # getopt.getopt() on Python 3 deals with unicodes internally so we cannot
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
    95
    # pass bytes there. Passing unicodes will result in unicodes as return
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
    96
    # values which we need to convert again to bytes.
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
    97
    def getoptb(args, shortlist, namelist):
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
    98
        args = [a.decode('latin-1') for a in args]
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
    99
        shortlist = shortlist.decode('latin-1')
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   100
        namelist = [a.decode('latin-1') for a in namelist]
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   101
        opts, args = getopt.getopt(args, shortlist, namelist)
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   102
        opts = [(a[0].encode('latin-1'), a[1].encode('latin-1'))
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   103
                for a in opts]
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   104
        args = [a.encode('latin-1') for a in args]
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   105
        return opts, args
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   106
30579
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   107
    # keys of keyword arguments in Python need to be strings which are unicodes
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   108
    # Python 3. This function takes keyword arguments, convert the keys to str.
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   109
    def strkwargs(dic):
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   110
        dic = dict((k.decode('latin-1'), v) for k, v in dic.iteritems())
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   111
        return dic
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   112
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   113
    # keys of keyword arguments need to be unicode while passing into
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   114
    # a function. This function helps us to convert those keys back to bytes
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   115
    # again as we need to deal with bytes.
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   116
    def byteskwargs(dic):
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   117
        dic = dict((k.encode('latin-1'), v) for k, v in dic.iteritems())
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   118
        return dic
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   119
30032
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
   120
else:
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
   121
    def sysstr(s):
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
   122
        return s
2219f4f82ede pycompat: extract function that converts attribute or encoding name to str
Yuya Nishihara <yuya@tcha.org>
parents: 30031
diff changeset
   123
30133
f6dcda7505f9 pycompat: only accept a bytestring filepath in Python 2
Martijn Pieters <mjpieters@fb.com>
parents: 30119
diff changeset
   124
    # Partial backport from os.py in Python 3, which only accepts bytes.
f6dcda7505f9 pycompat: only accept a bytestring filepath in Python 2
Martijn Pieters <mjpieters@fb.com>
parents: 30119
diff changeset
   125
    # In Python 2, our paths should only ever be bytes, a unicode path
f6dcda7505f9 pycompat: only accept a bytestring filepath in Python 2
Martijn Pieters <mjpieters@fb.com>
parents: 30119
diff changeset
   126
    # indicates a bug.
f6dcda7505f9 pycompat: only accept a bytestring filepath in Python 2
Martijn Pieters <mjpieters@fb.com>
parents: 30119
diff changeset
   127
    def fsencode(filename):
f6dcda7505f9 pycompat: only accept a bytestring filepath in Python 2
Martijn Pieters <mjpieters@fb.com>
parents: 30119
diff changeset
   128
        if isinstance(filename, str):
f6dcda7505f9 pycompat: only accept a bytestring filepath in Python 2
Martijn Pieters <mjpieters@fb.com>
parents: 30119
diff changeset
   129
            return filename
30119
f4a5e0e86a7e py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents: 30086
diff changeset
   130
        else:
30133
f6dcda7505f9 pycompat: only accept a bytestring filepath in Python 2
Martijn Pieters <mjpieters@fb.com>
parents: 30119
diff changeset
   131
            raise TypeError(
f6dcda7505f9 pycompat: only accept a bytestring filepath in Python 2
Martijn Pieters <mjpieters@fb.com>
parents: 30119
diff changeset
   132
                "expect str, not %s" % type(filename).__name__)
30119
f4a5e0e86a7e py3: add an os.fsencode backport to ease path handling
Martijn Pieters <mjpieters@fb.com>
parents: 30086
diff changeset
   133
30300
42af0590f4b9 py3: add os.fsdecode() as pycompat.fsdecode()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30133
diff changeset
   134
    # In Python 2, fsdecode() has a very chance to receive bytes. So it's
42af0590f4b9 py3: add os.fsdecode() as pycompat.fsdecode()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30133
diff changeset
   135
    # better not to touch Python 2 part as it's already working fine.
42af0590f4b9 py3: add os.fsdecode() as pycompat.fsdecode()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30133
diff changeset
   136
    def fsdecode(filename):
42af0590f4b9 py3: add os.fsdecode() as pycompat.fsdecode()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30133
diff changeset
   137
        return filename
42af0590f4b9 py3: add os.fsdecode() as pycompat.fsdecode()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30133
diff changeset
   138
30578
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   139
    def getoptb(args, shortlist, namelist):
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   140
        return getopt.getopt(args, shortlist, namelist)
c6ce11f2ee50 py3: make a bytes version of getopt.getopt()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30500
diff changeset
   141
30579
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   142
    def strkwargs(dic):
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   143
        return dic
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   144
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   145
    def byteskwargs(dic):
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   146
        return dic
fbc3f73dc802 py3: utility functions to convert keys of kwargs to bytes/unicodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30578
diff changeset
   147
30302
3874ddba1ab4 py3: add a bytes version of os.name
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30300
diff changeset
   148
    osname = os.name
30303
ad40d307a9f0 py3: have pycompat.ospathsep and pycompat.ossep
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30302
diff changeset
   149
    ospathsep = os.pathsep
ad40d307a9f0 py3: have pycompat.ospathsep and pycompat.ossep
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30302
diff changeset
   150
    ossep = os.sep
30623
c6026c20a3ce py3: have a bytes version of os.altsep
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30579
diff changeset
   151
    osaltsep = os.altsep
30472
277f4fe6d01a py3: provide bytes stdin/out/err through util module
Yuya Nishihara <yuya@tcha.org>
parents: 30334
diff changeset
   152
    stdin = sys.stdin
277f4fe6d01a py3: provide bytes stdin/out/err through util module
Yuya Nishihara <yuya@tcha.org>
parents: 30334
diff changeset
   153
    stdout = sys.stdout
277f4fe6d01a py3: provide bytes stdin/out/err through util module
Yuya Nishihara <yuya@tcha.org>
parents: 30334
diff changeset
   154
    stderr = sys.stderr
30330
a2f2f694dce9 py3: have bytes version of sys.argv
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30327
diff changeset
   155
    sysargv = sys.argv
30500
fc0cfe6c87d7 py3: add os.getcwdb() to have bytes path
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30472
diff changeset
   156
    getcwd = os.getcwd
30302
3874ddba1ab4 py3: add a bytes version of os.name
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30300
diff changeset
   157
29584
06587edd1233 pycompat: make pycompat demandimport friendly
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29566
diff changeset
   158
stringio = io.StringIO
28818
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
   159
empty = _queue.Empty
6041fb8f2da8 pycompat: add empty and queue to handle py3 divergence
timeless <timeless@mozdev.org>
parents:
diff changeset
   160
queue = _queue.Queue
28834
2fac032c1269 pycompat: alias xrange to range in py3
timeless <timeless@mozdev.org>
parents: 28833
diff changeset
   161
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   162
class _pycompatstub(object):
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   163
    def __init__(self):
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   164
        self._aliases = {}
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   165
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   166
    def _registeraliases(self, origin, items):
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   167
        """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
   168
        items = map(sysstr, items)
f3a1089654e3 pycompat: when setting attrs, ensure we use sysstr
Augie Fackler <augie@google.com>
parents: 30032
diff changeset
   169
        self._aliases.update(
f3a1089654e3 pycompat: when setting attrs, ensure we use sysstr
Augie Fackler <augie@google.com>
parents: 30032
diff changeset
   170
            (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
   171
            for item in items)
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   172
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   173
    def __getattr__(self, name):
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   174
        try:
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   175
            origin, item = self._aliases[name]
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   176
        except KeyError:
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   177
            raise AttributeError(name)
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   178
        self.__dict__[name] = obj = getattr(origin, item)
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   179
        return obj
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   180
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   181
httpserver = _pycompatstub()
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   182
urlreq = _pycompatstub()
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   183
urlerr = _pycompatstub()
30031
0f6d6fdd3c2a pycompat: provide 'ispy3' constant
Yuya Nishihara <yuya@tcha.org>
parents: 29801
diff changeset
   184
if not ispy3:
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   185
    import BaseHTTPServer
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   186
    import CGIHTTPServer
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   187
    import SimpleHTTPServer
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   188
    import urllib2
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   189
    import urllib
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   190
    urlreq._registeraliases(urllib, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   191
        "addclosehook",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   192
        "addinfourl",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   193
        "ftpwrapper",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   194
        "pathname2url",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   195
        "quote",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   196
        "splitattr",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   197
        "splitpasswd",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   198
        "splitport",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   199
        "splituser",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   200
        "unquote",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   201
        "url2pathname",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   202
        "urlencode",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   203
    ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   204
    urlreq._registeraliases(urllib2, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   205
        "AbstractHTTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   206
        "BaseHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   207
        "build_opener",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   208
        "FileHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   209
        "FTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   210
        "HTTPBasicAuthHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   211
        "HTTPDigestAuthHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   212
        "HTTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   213
        "HTTPPasswordMgrWithDefaultRealm",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   214
        "HTTPSHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   215
        "install_opener",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   216
        "ProxyHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   217
        "Request",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   218
        "urlopen",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   219
    ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   220
    urlerr._registeraliases(urllib2, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   221
        "HTTPError",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   222
        "URLError",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   223
    ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   224
    httpserver._registeraliases(BaseHTTPServer, (
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   225
        "HTTPServer",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   226
        "BaseHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   227
    ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   228
    httpserver._registeraliases(SimpleHTTPServer, (
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   229
        "SimpleHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   230
    ))
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   231
    httpserver._registeraliases(CGIHTTPServer, (
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   232
        "CGIHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   233
    ))
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   234
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   235
else:
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   236
    import urllib.request
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   237
    urlreq._registeraliases(urllib.request, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   238
        "AbstractHTTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   239
        "addclosehook",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   240
        "addinfourl",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   241
        "BaseHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   242
        "build_opener",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   243
        "FileHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   244
        "FTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   245
        "ftpwrapper",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   246
        "HTTPHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   247
        "HTTPSHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   248
        "install_opener",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   249
        "pathname2url",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   250
        "HTTPBasicAuthHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   251
        "HTTPDigestAuthHandler",
29414
2646fbba4ca7 pycompat: add HTTPPasswordMgrWithDefaultRealm to Python 3 block
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29405
diff changeset
   252
        "HTTPPasswordMgrWithDefaultRealm",
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   253
        "ProxyHandler",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   254
        "quote",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   255
        "Request",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   256
        "splitattr",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   257
        "splitpasswd",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   258
        "splitport",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   259
        "splituser",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   260
        "unquote",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   261
        "url2pathname",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   262
        "urlopen",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   263
    ))
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   264
    import urllib.error
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   265
    urlerr._registeraliases(urllib.error, (
28882
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   266
        "HTTPError",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   267
        "URLError",
800ec7c048b0 pycompat: add util.urlerr util.urlreq classes for py3 compat
timeless <timeless@mozdev.org>
parents: 28835
diff changeset
   268
    ))
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   269
    import http.server
29801
c63ab0524db7 pycompat: delay loading modules registered to stub
Yuya Nishihara <yuya@tcha.org>
parents: 29800
diff changeset
   270
    httpserver._registeraliases(http.server, (
29566
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   271
        "HTTPServer",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   272
        "BaseHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   273
        "SimpleHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   274
        "CGIHTTPRequestHandler",
075146e85bb6 py3: conditionalize BaseHTTPServer, SimpleHTTPServer and CGIHTTPServer import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29455
diff changeset
   275
    ))