summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2009-12-03 15:57:03 +0000
committerDavid Cournapeau <cournape@gmail.com>2009-12-03 15:57:03 +0000
commit8a1ba33c12bb73543a7ee29a7ec67386e1967656 (patch)
tree7675e338ac4c5375e86db43adacf277ec808dfc9
parentcf934f7deed917eb6a8d7bc8e160207f69c481c4 (diff)
downloadnumpy-8a1ba33c12bb73543a7ee29a7ec67386e1967656.tar.gz
Py3k: make template generators py3k importable.
-rw-r--r--numpy/distutils/conv_template.py15
-rw-r--r--numpy/distutils/from_template.py8
2 files changed, 14 insertions, 9 deletions
diff --git a/numpy/distutils/conv_template.py b/numpy/distutils/conv_template.py
index 6079a4f08..368cdd457 100644
--- a/numpy/distutils/conv_template.py
+++ b/numpy/distutils/conv_template.py
@@ -85,6 +85,8 @@ import os
import sys
import re
+from numpy.distutils.compat import get_exception
+
# names for replacement that are already global.
global_names = {}
@@ -218,7 +220,7 @@ def parse_string(astr, env, level, line) :
name = match.group(1)
try :
val = env[name]
- except KeyError, e :
+ except KeyError:
msg = 'line %d: no definition of key "%s"'%(line, name)
raise ValueError(msg)
return val
@@ -238,7 +240,8 @@ def parse_string(astr, env, level, line) :
code.append(replace_re.sub(replace, pref))
try :
envlist = parse_loop_header(head)
- except ValueError, e :
+ except ValueError:
+ e = get_exception()
msg = "line %d: %s" % (newline, e)
raise ValueError(msg)
for newenv in envlist :
@@ -273,7 +276,7 @@ def resolve_includes(source):
if not os.path.isabs(fn):
fn = os.path.join(d,fn)
if os.path.isfile(fn):
- print 'Including file',fn
+ print ('Including file',fn)
lines.extend(resolve_includes(fn))
else:
lines.append(line)
@@ -287,7 +290,8 @@ def process_file(source):
sourcefile = os.path.normcase(source).replace("\\","\\\\")
try:
code = process_str(''.join(lines))
- except ValueError, e:
+ except ValueError:
+ e = get_exception()
raise ValueError('In "%s" loop at %s' % (sourcefile, e))
return '#line 1 "%s"\n%s' % (sourcefile, code)
@@ -325,6 +329,7 @@ if __name__ == "__main__":
allstr = fid.read()
try:
writestr = process_str(allstr)
- except ValueError, e:
+ except ValueError:
+ e = get_exception()
raise ValueError("In %s loop at %s" % (file, e))
outfile.write(writestr)
diff --git a/numpy/distutils/from_template.py b/numpy/distutils/from_template.py
index 2f900b566..413f0721d 100644
--- a/numpy/distutils/from_template.py
+++ b/numpy/distutils/from_template.py
@@ -152,7 +152,7 @@ def expand_sub(substr,names):
if r not in rules:
thelist = lnames.get(r,names.get(r,None))
if thelist is None:
- raise ValueError,'No replicates found for <%s>' % (r)
+ raise ValueError('No replicates found for <%s>' % (r))
if r not in names and not thelist.startswith('_'):
names[r] = thelist
rule = [i.replace('@comma@',',') for i in thelist.split(',')]
@@ -165,10 +165,10 @@ def expand_sub(substr,names):
elif num == numsubs:
rules[r] = rule
else:
- print "Mismatch in number of replacements (base <%s=%s>)"\
+ print("Mismatch in number of replacements (base <%s=%s>)"\
" for <%s=%s>. Ignoring." % (base_rule,
','.join(rules[base_rule]),
- r,thelist)
+ r,thelist))
if not rules:
return substr
@@ -215,7 +215,7 @@ def resolve_includes(source):
if not os.path.isabs(fn):
fn = os.path.join(d,fn)
if os.path.isfile(fn):
- print 'Including file',fn
+ print ('Including file',fn)
lines.extend(resolve_includes(fn))
else:
lines.append(line)