is_py3k() -> is_py3k

This commit is contained in:
David Halter
2012-09-06 02:38:57 +02:00
parent 0008e2c703
commit 18686c1d63
5 changed files with 13 additions and 14 deletions

View File

@@ -4,8 +4,7 @@ python versions.
"""
import sys
def is_py3k():
return sys.hexversion >= 0x03000000
is_py3k = sys.hexversion >= 0x03000000
is_py25 = sys.hexversion < 0x02060000
@@ -63,7 +62,7 @@ except NameError:
return s.decode("utf-8")
# exec function
if is_py3k():
if is_py3k:
def exec_function(source, global_map):
exec(source, global_map)
else:
@@ -72,7 +71,7 @@ else:
# tokenize function
import tokenize
if is_py3k():
if is_py3k:
tokenize_func = tokenize.tokenize
else:
tokenize_func = tokenize.generate_tokens
@@ -84,7 +83,7 @@ except ImportError:
from io import BytesIO
# hasattr function used because python
if is_py3k():
if is_py3k:
hasattr = hasattr
else:
def hasattr(obj, name):

View File

@@ -3,7 +3,7 @@ from _compatibility import exec_function, is_py3k
import re
import sys
import os
if is_py3k():
if is_py3k:
import io
else:
import types
@@ -78,7 +78,7 @@ class Parser(CachedModule):
# TODO things like dbg: ('not working', 'tuple of integers')
}
if is_py3k():
if is_py3k:
map_types['file object'] = 'import io; return io.TextIOWrapper(file)'
module_cache = {}
@@ -170,14 +170,14 @@ class Parser(CachedModule):
try:
name = self.name
if name == '__builtin__' and not is_py3k():
if name == '__builtin__' and not is_py3k:
name = 'builtins'
f = open(os.path.sep.join(['mixin', name]) + '.py')
except IOError:
return {}
else:
mixin_dct = process_code(f.read())
if is_py3k() and self.name == _Builtin.name:
if is_py3k and self.name == _Builtin.name:
# in the case of Py3k xrange is now range
mixin_dct['range'] = mixin_dct['xrange']
return mixin_dct
@@ -309,7 +309,7 @@ class Parser(CachedModule):
# variables
for name, value in stmts.items():
if is_py3k():
if is_py3k:
file_type = io.TextIOWrapper
else:
file_type = types.FileType
@@ -401,7 +401,7 @@ def parse_function_doc(func):
class _Builtin(object):
""" The builtin scope / module """
# Python 3 compatibility
if is_py3k():
if is_py3k:
name = 'builtins'
else:
name = '__builtin__'

View File

@@ -1168,7 +1168,7 @@ def get_iterator_types(inputs):
result += gen.get_index_types()
elif isinstance(gen, Instance):
# __iter__ returned an instance.
name = '__next__' if is_py3k() else 'next'
name = '__next__' if is_py3k else 'next'
try:
result += gen.execute_subscope_by_name(name)
except KeyError:

View File

@@ -14,7 +14,7 @@ except ImportError:
# Python 2.5
pydoc_topics = None
if is_py3k():
if is_py3k:
keys = keyword.kwlist
else:
keys = keyword.kwlist + ['None', 'False', 'True']

View File

@@ -1049,7 +1049,7 @@ class PyFuzzyParser(object):
self.user_stmt = None
self.code = code + '\n' # end with \n, because the parser needs it
self.no_docstr = no_docstr
if is_py3k():
if is_py3k:
self.code = self.code.encode()
# initialize global Scope