aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/compat.py
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2011-06-20 22:55:16 +0100
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2011-06-20 22:55:16 +0100
commit58a658b26d1c95b31d02050dcccd648d2e4ce27b (patch)
treeb9d3e7de6f6d23b91a7afecde3491e99d8cc7069 /setuptools/compat.py
parente63f3e7d864b26529d6b197e053b4084be20decf (diff)
downloadexternal_python_setuptools-58a658b26d1c95b31d02050dcccd648d2e4ce27b.tar.gz
external_python_setuptools-58a658b26d1c95b31d02050dcccd648d2e4ce27b.tar.bz2
external_python_setuptools-58a658b26d1c95b31d02050dcccd648d2e4ce27b.zip
Changes to support 2.x and 3.x in the same codebase.
--HG-- branch : distribute extra : rebase_source : 7d3608edee54a43789f0574d702fb839628b5071
Diffstat (limited to 'setuptools/compat.py')
-rw-r--r--setuptools/compat.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/setuptools/compat.py b/setuptools/compat.py
new file mode 100644
index 00000000..dfbb314d
--- /dev/null
+++ b/setuptools/compat.py
@@ -0,0 +1,73 @@
+import sys
+
+if sys.version_info[0] < 3:
+ PY3 = False
+
+ basestring = basestring
+ import __builtin__ as builtins
+ import ConfigParser
+ from cStringIO 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
+ 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
+ import urllib2
+ from urllib2 import urlopen, HTTPError, URLError, unquote, splituser
+ from urlparse import urlparse, urlunparse, urljoin
+ xrange = xrange
+
+ 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""")
+
+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
+ 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, unquote, splituser, urljoin
+ xrange = range
+
+ def execfile(fn, globs, locs):
+ exec_(compile(open(fn).read(), fn, 'exec'), globs, locs)