changes so that python3 will run with the builtins, because in py3k range = old xrange

This commit is contained in:
David Halter
2012-08-11 00:06:12 +02:00
parent e41c4c6cc3
commit f95245a3a0

View File

@@ -1,7 +1,9 @@
from _compatibility import exec_function, is_py3k
import re import re
import sys import sys
import os import os
if sys.hexversion >= 0x03000000: if is_py3k():
import io import io
else: else:
import types import types
@@ -10,7 +12,6 @@ import inspect
import debug import debug
import parsing import parsing
from _compatibility import exec_function
module_find_path = sys.path[1:] module_find_path = sys.path[1:]
@@ -73,7 +74,7 @@ class Parser(CachedModule):
# TODO things like dbg: ('not working', 'tuple of integers') # TODO things like dbg: ('not working', 'tuple of integers')
} }
if sys.hexversion >= 0x03000000: if is_py3k():
map_types['file object'] = 'import io; return io.TextIOWrapper(file)' map_types['file object'] = 'import io; return io.TextIOWrapper(file)'
module_cache = {} module_cache = {}
@@ -163,13 +164,17 @@ class Parser(CachedModule):
try: try:
name = self.name name = self.name
if name == '__builtin__' and sys.hexversion < 0x03000000: if name == '__builtin__' and not is_py3k():
name = 'builtins' name = 'builtins'
f = open(os.path.sep.join(['mixin', name]) + '.py') f = open(os.path.sep.join(['mixin', name]) + '.py')
except IOError: except IOError:
return {} return {}
else: else:
return process_code(f.read()) mixin_dct = process_code(f.read())
if is_py3k():
# in the case of Py3k xrange is now range
mixin_dct['range'] = mixin_dct['xrange']
return mixin_dct
def _generate_code(self, scope, mixin_funcs, depth=0): def _generate_code(self, scope, mixin_funcs, depth=0):
""" """
@@ -294,7 +299,7 @@ class Parser(CachedModule):
# variables # variables
for name, value in stmts.items(): for name, value in stmts.items():
if sys.hexversion >= 0x03000000: if is_py3k():
file_type = io.TextIOWrapper file_type = io.TextIOWrapper
else: else:
file_type = types.FileType file_type = types.FileType
@@ -379,7 +384,7 @@ def parse_function_doc(func):
class _Builtin(object): class _Builtin(object):
# Python 3 compatibility # Python 3 compatibility
if sys.hexversion >= 0x03000000: if is_py3k():
name = 'builtins' name = 'builtins'
else: else:
name = '__builtin__' name = '__builtin__'