Commit 9498ab65 authored by Stefan Behnel's avatar Stefan Behnel

replace xrange() by range() to make it work in Py2/Py3

parent 9c7d4b13
......@@ -4769,7 +4769,7 @@ class SimpleCallNode(CallNode):
# Coerce arguments
some_args_in_temps = False
for i in xrange(min(max_nargs, actual_nargs)):
for i in range(min(max_nargs, actual_nargs)):
formal_arg = func_type.args[i]
formal_type = formal_arg.type
arg = args[i].coerce_to(formal_type, env)
......@@ -4799,7 +4799,7 @@ class SimpleCallNode(CallNode):
args[i] = arg
# handle additional varargs parameters
for i in xrange(max_nargs, actual_nargs):
for i in range(max_nargs, actual_nargs):
arg = args[i]
if arg.type.is_pyobject:
arg_ctype = arg.type.default_coerced_ctype()
......@@ -4817,7 +4817,7 @@ class SimpleCallNode(CallNode):
# sure they are either all temps or all not temps (except
# for the last argument, which is evaluated last in any
# case)
for i in xrange(actual_nargs-1):
for i in range(actual_nargs-1):
if i == 0 and self.self is not None:
continue # self is ok
arg = args[i]
......@@ -5207,7 +5207,7 @@ class InlinedDefNodeCallNode(CallNode):
# Coerce arguments
some_args_in_temps = False
for i in xrange(actual_nargs):
for i in range(actual_nargs):
formal_type = func_type.args[i].type
arg = self.args[i].coerce_to(formal_type, env)
if arg.is_temp:
......@@ -5234,7 +5234,7 @@ class InlinedDefNodeCallNode(CallNode):
# sure they are either all temps or all not temps (except
# for the last argument, which is evaluated last in any
# case)
for i in xrange(actual_nargs-1):
for i in range(actual_nargs-1):
arg = self.args[i]
if arg.nonlocally_immutable():
# locals, C functions, unassignable types are safe.
......@@ -6503,7 +6503,7 @@ class SequenceNode(ExprNode):
else:
offset = ''
for i in xrange(arg_count):
for i in range(arg_count):
arg = self.args[i]
if c_mult or not arg.result_in_temp():
code.put_incref(arg.result(), arg.ctype())
......
......@@ -790,7 +790,7 @@ def validate_axes_specs(positions, specs, is_c_contig, is_f_contig):
if access == 'ptr':
last_indirect_dimension = idx
for idx, pos, (access, packing) in zip(xrange(len(specs)), positions, specs):
for idx, pos, (access, packing) in zip(range(len(specs)), positions, specs):
if not (access in access_specs and
packing in packing_specs):
......
......@@ -6684,7 +6684,7 @@ class TryExceptStatNode(StatNode):
try_end_label = code.new_label('try_end')
exc_save_vars = [code.funcstate.allocate_temp(py_object_type, False)
for _ in xrange(3)]
for _ in range(3)]
code.mark_pos(self.pos)
code.putln("{")
save_exc = code.insertion_point()
......@@ -6869,7 +6869,7 @@ class ExceptClauseNode(Node):
exc_vars = [code.funcstate.allocate_temp(py_object_type,
manage_ref=True)
for _ in xrange(3)]
for _ in range(3)]
code.put_add_traceback(self.function_name)
# We always have to fetch the exception value even if
# there is no target, because this also normalises the
......
......@@ -420,11 +420,11 @@ def sort_common_subsequences(items):
for pos, item in enumerate(items):
key = item[1] # the ResultRefNode which has already been injected into the sequences
new_pos = pos
for i in xrange(pos-1, -1, -1):
for i in range(pos-1, -1, -1):
if lower_than(key, items[i][0]):
new_pos = i
if new_pos != pos:
for i in xrange(pos, new_pos, -1):
for i in range(pos, new_pos, -1):
items[i] = items[i-1]
items[new_pos] = item
......@@ -460,7 +460,7 @@ def flatten_parallel_assignments(input, output):
rhs_args = unpack_string_to_character_literals(rhs)
rhs_size = len(rhs_args)
lhs_targets = [ [] for _ in xrange(rhs_size) ]
lhs_targets = [[] for _ in range(rhs_size)]
starred_assignments = []
for lhs in input[:-1]:
if not lhs.is_sequence_constructor:
......
......@@ -3450,7 +3450,7 @@ def print_parse_tree(f, node, level, key = None):
t = type(node)
if t is tuple:
f.write("(%s @ %s\n" % (node[0], node[1]))
for i in xrange(2, len(node)):
for i in range(2, len(node)):
print_parse_tree(f, node[i], level+1)
f.write("%s)\n" % ind)
return
......@@ -3466,7 +3466,7 @@ def print_parse_tree(f, node, level, key = None):
return
elif t is list:
f.write("[\n")
for i in xrange(len(node)):
for i in range(len(node)):
print_parse_tree(f, node[i], level+1)
f.write("%s]\n" % ind)
return
......
......@@ -127,7 +127,7 @@ class Signature(object):
def function_type(self, self_arg_override=None):
# Construct a C function type descriptor for this signature
args = []
for i in xrange(self.num_fixed_args()):
for i in range(self.num_fixed_args()):
if self_arg_override is not None and self.is_self_arg(i):
assert isinstance(self_arg_override, PyrexTypes.CFuncTypeArg)
args.append(self_arg_override)
......
......@@ -118,7 +118,7 @@ def safety_limit(val):
def safe_range(val):
# As per range, but don't trust the value too much: cap it to a safety
# threshold in case the data was corrupted
return xrange(safety_limit(val))
return range(safety_limit(val))
def write_unicode(file, text):
......
......@@ -87,9 +87,7 @@ def CodeRanges(code_list):
Given a list of codes as returned by chars_to_ranges, return
an RE which will match a character in any of the ranges.
"""
re_list = []
for i in xrange(0, len(code_list), 2):
re_list.append(CodeRange(code_list[i], code_list[i + 1]))
re_list = [CodeRange(code_list[i], code_list[i + 1]) for i in range(0, len(code_list), 2)]
return Alt(*re_list)
......@@ -307,8 +305,7 @@ class Seq(RE):
def __init__(self, *re_list):
nullable = 1
for i in xrange(len(re_list)):
re = re_list[i]
for i, re in enumerate(re_list):
self.check_re(i, re)
nullable = nullable and re.nullable
self.re_list = re_list
......@@ -332,12 +329,11 @@ class Seq(RE):
else:
s1 = initial_state
n = len(re_list)
for i in xrange(n):
for i, re in enumerate(re_list):
if i < n - 1:
s2 = m.new_state()
else:
s2 = final_state
re = re_list[i]
re.build_machine(m, s1, s2, match_bol, nocase)
s1 = s2
match_bol = re.match_nl or (match_bol and re.nullable)
......
......@@ -104,7 +104,7 @@ class REParser(object):
if self.c == '-' and self.lookahead(1) != ']':
self.next()
c2 = self.get()
for a in xrange(ord(c1), ord(c2) + 1):
for a in range(ord(c1), ord(c2) + 1):
char_list.append(chr(a))
else:
char_list.append(c1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment