diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2013-06-15 15:34:53 +0100 |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2013-06-15 15:34:53 +0100 |
commit | 8e657eac1ef02faedca99df319fff6b63f4a4305 (patch) | |
tree | f3f2ed97342421c6b65c9caaab8ae5d830f04059 /setuptools/compat.py | |
parent | c04abca662dcbffd00d928e06fbf32b9f49f8e57 (diff) | |
download | external_python_setuptools-8e657eac1ef02faedca99df319fff6b63f4a4305.tar.gz external_python_setuptools-8e657eac1ef02faedca99df319fff6b63f4a4305.tar.bz2 external_python_setuptools-8e657eac1ef02faedca99df319fff6b63f4a4305.zip |
Initial commit. All tests pass on 2.7, 3.2 and 3.3, though there are some atexit errors in the multiprocessing module in 2.7/3.2 (seemingly unrelated to setuptools).
--HG--
branch : single-codebase
Diffstat (limited to 'setuptools/compat.py')
-rw-r--r-- | setuptools/compat.py | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/setuptools/compat.py b/setuptools/compat.py new file mode 100644 index 00000000..49438502 --- /dev/null +++ b/setuptools/compat.py @@ -0,0 +1,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 |