# Pyrex - Parse tree nodes
#
-import string, sys, os, time, copy
+import sys, os, time, copy
import Code
import Builtin
arg_decls = ["void"]
if cname is None:
cname = self.entry.func_cname
- entity = type.function_header_code(cname, string.join(arg_decls, ", "))
+ entity = type.function_header_code(cname, ', '.join(arg_decls))
if visibility == 'public':
dll_linkage = "DL_EXPORT"
else:
def ForStatNode(pos, **kw):
- if kw.has_key('iterator'):
+ if 'iterator' in kw:
return ForInStatNode(pos, **kw)
else:
return ForFromStatNode(pos, **kw)
__revision__ = "$Id:$"
-import sys, os, string, re
+import sys, os, re
from types import *
from distutils.core import Command
from distutils.errors import *
self.pyrex_include_dirs = []
elif type(self.pyrex_include_dirs) is StringType:
self.pyrex_include_dirs = \
- string.split(self.pyrex_include_dirs, os.pathsep)
+ self.pyrex_include_dirs.split(os.pathsep)
# finalize_options ()
def build_extensions(self):
__revision__ = "$Id:$"
-import os, string, sys
+import os, sys
from types import *
import distutils.extension as _Extension
# Pyrex -- Mac system interface
#
-import os, sys, string
+import os, sys
import aetools
from aetools import TalkTo
from StdSuites.Standard_Suite import Standard_Suite_Events as Standard_Suite
errn, stat, stdout, stderr = result
if errn:
raise CCompilerError("ToolServer error: %s" % errn)
- stdout = string.replace(stdout, "\r", "\n")
- stderr = string.replace(stderr, "\r", "\n")
+ stdout = stdout.replace("\r", "\n")
+ stderr = stderr.replace("\r", "\n")
if stdout:
#print "<<< Begin ToolServer StdOut >>>"
sys.stderr.write(stdout)
command = "%s -opt %s -nomapcr -w off -r %s %s -o %s" % (
c_compiler,
c_optimizations,
- string.join(include_options),
+ ' '.join(include_options),
c_file,
o_file,
#e_file
out_file = replace_suffix(obj_files[0], shared_lib_suffix)
command = "%s -xm s -export all %s %s %s -o %s" % (
c_linker,
- string.join(obj_files),
+ ' '.join(obj_files),
pythoncore,
- string.join(libraries),
+ ' '.join(libraries),
out_file)
stat = do_toolserver_command(command)
if stat:
_code = 'misc'
_subcode = 'dosc'
- if _arguments: raise TypeError, 'No optional args expected'
+ if _arguments: raise TypeError('No optional args expected')
_arguments['----'] = _object
stat = 0
stdout = ""
stderr = ""
- if _arguments.has_key('errn'):
+ if 'errn' in _arguments:
errn = _arguments['errn']
if errn:
errn = aetools.decodeerror(_arguments)
- if _arguments.has_key('stat'):
+ if 'stat' in _arguments:
stat = _arguments['stat']
- if _arguments.has_key('----'):
+ if '----' in _arguments:
stdout = _arguments['----']
- if _arguments.has_key('diag'):
+ if 'diag' in _arguments:
stderr = _arguments['diag']
return (errn, stat, stdout, stderr)
# Seed the process using the initial states of the old machine.
# Make the corresponding new states into initial states of the new
# machine with the same names.
- for (key, old_state) in old_machine.initial_states.items():
+ for (key, old_state) in old_machine.initial_states.iteritems():
new_state = state_map.old_to_new(epsilon_closure(old_state))
new_machine.make_initial_state(key, new_state)
# Tricky bit here: we add things to the end of this list while we're
# iterating over it. The iteration stops when closure is achieved.
for new_state in new_machine.states:
transitions = TransitionMap()
- for old_state in state_map.new_to_old(new_state).keys():
- for event, old_target_states in old_state.transitions.items():
+ for old_state in state_map.new_to_old(new_state):
+ for event, old_target_states in old_state.transitions.iteritems():
if event and old_target_states:
transitions.add_set(event, set_epsilon_closure(old_target_states))
- for event, old_states in transitions.items():
+ for event, old_states in transitions.iteritems():
new_machine.add_transitions(new_state, event, state_map.old_to_new(old_states))
if debug:
debug.write("\n===== State Mapping =====\n")
closures of its member states.
"""
result = {}
- for state1 in state_set.keys():
- for state2 in epsilon_closure(state1).keys():
+ for state1 in state_set:
+ for state2 in epsilon_closure(state1):
result[state2] = 1
return result
state_set[state] = 1
state_set_2 = state.transitions.get_epsilon()
if state_set_2:
- for state2 in state_set_2.keys():
+ for state2 in state_set_2:
add_to_epsilon_closure(state_set, state2)
class StateMap(object):
def highest_priority_action(self, state_set):
best_action = None
best_priority = LOWEST_PRIORITY
- for state in state_set.keys():
+ for state in state_set:
priority = state.action_priority
if priority > best_priority:
best_action = state.action
Convert a set of states into a uniquified
sorted tuple suitable for use as a dictionary key.
"""
- lst = state_set.keys()
+ lst = list(state_set)
lst.sort()
return tuple(lst)
#
#=======================================================================
-import string
import sys
from sys import maxint
from types import TupleType
file.write("Plex.Machine:\n")
if self.initial_states is not None:
file.write(" Initial states:\n")
- for (name, state) in self.initial_states.items():
+ for (name, state) in self.initial_states.iteritems():
file.write(" '%s': %d\n" % (name, state.number))
for s in self.states:
s.dump(file)
return "State %d" % self.number
def dump(self, file):
- import string
# Header
file.write(" State %d:\n" % self.number)
# Transitions
for old_state in old_machine.states:
new_state = self.new_state()
old_to_new[old_state] = new_state
- for name, old_state in old_machine.initial_states.items():
+ for name, old_state in old_machine.initial_states.iteritems():
initial_states[name] = old_to_new[old_state]
for old_state in old_machine.states:
new_state = old_to_new[old_state]
- for event, old_state_set in old_state.transitions.items():
+ for event, old_state_set in old_state.transitions.iteritems():
if old_state_set:
new_state[event] = old_to_new[old_state_set.keys()[0]]
else:
def dump(self, file):
file.write("Plex.FastMachine:\n")
file.write(" Initial states:\n")
- for name, state in self.initial_states.items():
+ for name, state in self.initial_states.iteritems():
file.write(" %s: %s\n" % (repr(name), state['number']))
for state in self.states:
self.dump_state(state, file)
def dump_state(self, state, file):
- import string
# Header
file.write(" State %d:\n" % state['number'])
# Transitions
def dump_transitions(self, state, file):
chars_leading_to_state = {}
special_to_state = {}
- for (c, s) in state.items():
+ for (c, s) in state.iteritems():
if len(c) == 1:
chars = chars_leading_to_state.get(id(s), None)
if chars is None:
return tuple(result)
def ranges_to_string(self, range_list):
- return string.join(map(self.range_to_string, range_list), ",")
+ return ','.join(map(self.range_to_string, range_list))
def range_to_string(self, range_tuple):
(c1, c2) = range_tuple
#=======================================================================
import array
-import string
import types
from sys import maxint
match_bol = re.match_nl or (match_bol and re.nullable)
def calc_str(self):
- return "Seq(%s)" % string.join(map(str, self.re_list), ",")
+ return "Seq(%s)" % ','.join(map(str, self.re_list))
class Alt(RE):
re.build_machine(m, initial_state, final_state, 0, nocase)
def calc_str(self):
- return "Alt(%s)" % string.join(map(str, self.re_list), ",")
+ return "Alt(%s)" % ','.join(map(str, self.re_list))
class Rep1(RE):
"""
Str1(s) is an RE which matches the literal string |s|.
"""
- result = apply(Seq, tuple(map(Char, s)))
+ result = Seq(*tuple(map(Char, s)))
result.str = "Str(%s)" % repr(s)
return result
if len(strs) == 1:
return Str1(strs[0])
else:
- result = apply(Alt, tuple(map(Str1, strs)))
- result.str = "Str(%s)" % string.join(map(repr, strs), ",")
+ result = Alt(*tuple(map(Str1, strs)))
+ result.str = "Str(%s)" % ','.join(map(repr, strs))
return result
def Any(s):
ranges = []
for i in range(0, len(s1), 2):
ranges.append(CodeRange(ord(s1[i]), ord(s1[i+1]) + 1))
- result = apply(Alt, tuple(ranges))
+ result = Alt(*ranges)
result.str = "Range(%s)" % repr(s1)
return result
while self.c == '|':
self.next()
re_list.append(self.parse_seq())
- re = apply(Alt, tuple(re_list))
+ re = Alt(*re_list)
return re
def parse_seq(self):
re_list = []
while not self.end and not self.c in "|)":
re_list.append(self.parse_mod())
- return apply(Seq, tuple(re_list))
+ return Seq(*re_list)
def parse_mod(self):
"""Parse a primitive regexp followed by *, +, ? modifiers."""
#
from copy import copy
-import string
from sys import maxint
from types import TupleType
"""
return self.special.get('', none)
- def items(self,
+ def iteritems(self,
len = len):
"""
- Return the mapping as a list of ((code1, code2), state_set) and
+ Return the mapping as an iterable of ((code1, code2), state_set) and
(special_event, state_set) pairs.
"""
result = []
result.append(((code0, code1), set))
code0 = code1
i = i + 2
- for event, set in self.special.items():
+ for event, set in self.special.iteritems():
if set:
result.append((event, set))
- return result
+ return iter(result)
# ------------------- Private methods --------------------
map_strs.append(state_set_str(map[i]))
i = i + 1
special_strs = {}
- for event, set in self.special.items():
+ for event, set in self.special.iteritems():
special_strs[event] = state_set_str(set)
return "[%s]+%s" % (
- string.join(map_strs, ","),
+ ','.join(map_strs),
special_strs
)
while i < n:
self.dump_range(map[i], map[i + 2], map[i + 1], file)
i = i + 2
- for event, set in self.special.items():
+ for event, set in self.special.iteritems():
if set:
if not event:
event = 'empty'
# set1[state] = 1
def state_set_str(set):
- state_list = set.keys()
- str_list = []
- for state in state_list:
- str_list.append("S%d" % state.number)
- return "[%s]" % string.join(str_list, ",")
+ return "[%s]" % ','.join(["S%d" % state.number for state in set])
def __getitem__(self, ix):
if ix < 0:
- raise IndexError, "negative indexing not allowed in C"
+ raise IndexError("negative indexing not allowed in C")
return self._items[ix]
def __setitem__(self, ix, value):
if ix < 0:
- raise IndexError, "negative indexing not allowed in C"
+ raise IndexError("negative indexing not allowed in C")
self._items[ix] = cast(self._basetype, value)
class ArrayType(PointerType):
class StructType(CythonType):
def __init__(self, **data):
- for key, value in data.items():
+ for key, value in data.iteritems():
setattr(self, key, value)
def __setattr__(self, key, value):
if key in self._members:
self.__dict__[key] = cast(self._members[key], value)
else:
- raise AttributeError, "Struct has no member '%s'" % key
+ raise AttributeError("Struct has no member '%s'" % key)
class UnionType(CythonType):
def __init__(self, **data):
if len(data) > 0:
- raise AttributeError, "Union can only store one field at a time."
- for key, value in data.items():
+ raise AttributeError("Union can only store one field at a time.")
+ for key, value in data.iteritems():
setattr(self, key, value)
def __setattr__(self, key, value):
elif key in self._members:
self.__dict__ = {key: cast(self._members[key], value)}
else:
- raise AttributeError, "Union has no member '%s'" % key
+ raise AttributeError("Union has no member '%s'" % key)
def pointer(basetype):
class PointerInstance(PointerType):
def struct(**members):
class StructInstance(StructType):
_members = members
- for key in members.keys():
+ for key in members:
setattr(StructInstance, key, None)
return StructInstance
def union(**members):
class UnionInstance(UnionType):
_members = members
- for key in members.keys():
+ for key in members:
setattr(UnionInstance, key, None)
return UnionInstance