aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/compat.py
blob: 49438502fc2f0c16aa88e3688b7a0dbe46b8baaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import sys

if sys.version_info[0] < 3:
    PY3 = False

    basestring = basestring
    import __builtin__ as builtins
    import ConfigParser
    from StringIO import StringIO
    BytesIO = StringIO
    execfile = execfile
    func_code = lambda o: o.func_code
    func_globals = lambda o: o.func_globals
    im_func = lambda o: o.im_func
    from htmlentitydefs import name2codepoint
    import httplib
    from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
    from SimpleHTTPServer import SimpleHTTPRequestHandler
    iteritems = lambda o: o.iteritems()
    long_type = long
    maxsize = sys.maxint
    next = lambda o: o.next()
    numeric_types = (int, long, float)
    reduce = reduce
    unichr = unichr
    unicode = unicode
    from urllib import url2pathname, quote # Python 2.4 has no quote in urllib2
    import urllib2
    from urllib2 import urlopen, HTTPError, URLError, unquote, splituser
    from urlparse import urlparse, urlunparse, urljoin
    xrange = xrange
    from itertools import ifilterfalse

    def exec_(code, globs=None, locs=None):
        if globs is None:
            frame = sys._getframe(1)
            globs = frame.f_globals
            if locs is None:
                locs = frame.f_locals
            del frame
        elif locs is None:
            locs = globs
        exec("""exec code in globs, locs""")

    exec_("""def reraise(tp, value, tb=None):
    raise tp, value, tb""")
else:
    PY3 = True

    basestring = str
    import builtins
    import configparser as ConfigParser
    exec_ = eval('exec')
    from io import StringIO, BytesIO
    func_code = lambda o: o.__code__
    func_globals = lambda o: o.__globals__
    im_func = lambda o: o.__func__
    from html.entities import name2codepoint
    import http.client as httplib
    from http.server import HTTPServer, SimpleHTTPRequestHandler, BaseHTTPRequestHandler
    iteritems = lambda o: o.items()
    long_type = int
    maxsize = sys.maxsize
    next = next
    numeric_types = (int, float)
    from functools import reduce
    unichr = chr
    unicode = str
    from urllib.error import HTTPError, URLError
    import urllib.request as urllib2
    from urllib.request import urlopen, url2pathname
    from urllib.parse import urlparse, urlunparse, quote, unquote, splituser, urljoin
    xrange = range
    from itertools import filterfalse as ifilterfalse

    def execfile(fn, globs=None, locs=None):
        if globs is None:
            globs = globals()
        if locs is None:
            locs = globs
        f = open(fn)
        try:
            source = f.read()
        finally:
            f.close()
        exec_(compile(source, fn, 'exec'), globs, locs)

    def reraise(tp, value, tb=None):
        if value.__traceback__ is not tb:
            raise value.with_traceback(tb)
        raise value