~mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
math/mpgen, symm/multigen: Fix the various build scripts for Python 3.
[catacomb]
/
symm
/
multigen
diff --git
a/symm/multigen
b/symm/multigen
index
4c1921e
..
8af0f10
100755
(executable)
--- a/
symm/multigen
+++ b/
symm/multigen
@@
-30,7
+30,9
@@
import itertools as IT
import optparse as OP
import os as OS
import re as RX
import optparse as OP
import os as OS
import re as RX
-from cStringIO import StringIO
+import sys as SYS
+if SYS.version_info >= (3,): from io import StringIO
+else: from cStringIO import StringIO
from sys import argv, exit, stderr
###--------------------------------------------------------------------------
from sys import argv, exit, stderr
###--------------------------------------------------------------------------
@@
-49,6
+51,16
@@
def indexed(seq):
"""
return IT.izip(IT.count(), seq)
"""
return IT.izip(IT.count(), seq)
+if SYS.version_info >= (3,):
+ def func_name(func): return func.__name__
+ IT.izip = zip
+else:
+ def func_name(func): return func.func_name
+
+try: next
+except NameError:
+ def next(obj): return obj.next()
+
###--------------------------------------------------------------------------
### Reading the input values.
###--------------------------------------------------------------------------
### Reading the input values.
@@
-363,7
+375,7
@@
class SequenceTemplate (BasicTemplate):
if len(seq) == 1:
return seq[0]
else:
if len(seq) == 1:
return seq[0]
else:
- return super(SequenceTemplate, cls).__new__(cls,
seq = seq,
**kw)
+ return super(SequenceTemplate, cls).__new__(cls, **kw)
def __init__(me, seq, **kw):
"""
def __init__(me, seq, **kw):
"""
@@
-461,7
+473,7
@@
class ParseState (object):
Sets `curr' to the next line, or to None if the input is exhausted.
"""
Sets `curr' to the next line, or to None if the input is exhausted.
"""
- try: me.curr =
me._it.next(
)
+ try: me.curr =
next(me._it
)
except StopIteration: me.curr = None
else: me._i += 1
except StopIteration: me.curr = None
else: me._i += 1
@@
-504,7
+516,7
@@
def defop(func):
An operator function is given the raw value as an argument and should
return the transformed value.
"""
An operator function is given the raw value as an argument and should
return the transformed value.
"""
- name = func
.func_name
+ name = func
_name(func)
if name.startswith('op_'): name = name[3:]
OPMAP[name] = func
return func
if name.startswith('op_'): name = name[3:]
OPMAP[name] = func
return func
@@
-576,7
+588,7
@@
def parse_text(ps):
## object.
l = lit.getvalue()
if l: tt.append(LiteralTemplate(l))
## object.
l = lit.getvalue()
if l: tt.append(LiteralTemplate(l))
- lit.
reset(
)
+ lit.
seek(0
)
lit.truncate()
## Iterate over the lines of input.
lit.truncate()
## Iterate over the lines of input.
@@
-786,7
+798,7
@@
def filenames(filetempl):
## Main dispatch.
if opts.mode == 'list':
## Main dispatch.
if opts.mode == 'list':
- for file, cs in filenames(filetempl): print
file
+ for file, cs in filenames(filetempl): print
(file)
elif opts.mode == 'gen':
with open(opts.input) as f:
templ = RepeatTemplate(compile_template(opts.input, f.read()))
elif opts.mode == 'gen':
with open(opts.input) as f:
templ = RepeatTemplate(compile_template(opts.input, f.read()))