[Python-modules-commits] [fparser] 02/09: More py3

Alastair McKinstry mckinstry at moszumanska.debian.org
Fri Jul 28 10:45:31 UTC 2017


This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch dev-python3
in repository fparser.

commit aa644463569491161153a1982a499695d20e5dce
Author: Alastair McKinstry <mckinstry at debian.org>
Date:   Tue Jul 25 16:10:14 2017 +0100

    More py3
---
 src/fparser/readfortran.py    | 38 +++++++++++-----------
 src/fparser/splitline.py      | 26 ++++++++-------
 src/fparser/statements.py     | 75 ++++++++++++++++++++++---------------------
 src/fparser/tests/test_api.py |  3 +-
 4 files changed, 74 insertions(+), 68 deletions(-)

diff --git a/src/fparser/readfortran.py b/src/fparser/readfortran.py
index 4e6f282..825fa3e 100644
--- a/src/fparser/readfortran.py
+++ b/src/fparser/readfortran.py
@@ -82,11 +82,11 @@ Examples
     >>> reader = FortranFileReader(os.path.expanduser('~/src/blas/daxpy.f'))
     >>> print reader.next()
     line #1 'subroutine daxpy(n,da,dx,incx,dy,incy)'
-    >>> print `reader.next()`
+    >>> print repr(reader.next())
     Comment('c     constant times a vector plus a vector.\\nc     uses unrolled loops for increments equal to one.\\nc     jack dongarra, linpack, 3/11/78.\\nc     modified 12/3/93, array(1) declarations changed to array(*)',(3, 6))
-    >>> print `reader.next()`
+    >>> print repr(reader.next())
     Line('double precision dx(*),dy(*),da',(8, 8),'')
-    >>> print `reader.next()`
+    >>> print repr(reader.next())
     Line('integer i,incx,incy,ix,iy,m,mp1,n',(9, 9),'')
 
 Note that the ``.next()`` method may return `Line`, `SyntaxErrorLine`,
@@ -129,6 +129,8 @@ To read a Fortran code from a string, use `FortranStringReader` class::
 #Author: Pearu Peterson <pearu at cens.ioc.ee>
 #Created: May 2006
 
+from __future__ import print_function
+
 __all__ = ['FortranFileReader',
            'FortranStringReader',
            'FortranReaderError',
@@ -143,12 +145,12 @@ import sys
 import tempfile
 import traceback
 import logging
-from cStringIO import StringIO
+from io import StringIO
 from numpy.distutils.misc_util import yellow_text, red_text, blue_text
 
-from sourceinfo import get_source_info, get_source_info_str
-from splitline import String, string_replace_map, splitquote
-from utils import is_name
+from .sourceinfo import get_source_info, get_source_info_str
+from .splitline import String, string_replace_map, splitquote
+from .utils import is_name
 
 logger = logging.getLogger('fparser')
 
@@ -217,10 +219,10 @@ class Line(object):
 
     def __init__(self, line, linenospan, label, name, reader):
         self.line = line.strip()
-        assert self.line, `line, linenospan, label`
+        assert self.line, repr(line, linenospan, label)
         self.span = linenospan
-        assert label is None or isinstance(label,int),`label`
-        assert name is None or isinstance(name,str) and name!='',`name`
+        assert label is None or isinstance(label,int),repr(label)
+        assert name is None or isinstance(name,str) and name!='',repr(name)
         self.label = label
         self.name = name
         self.reader = reader
@@ -263,7 +265,7 @@ class Line(object):
             s += ' %s ' % (self.label)
         if self.name is not None:
             s += '%s: ' % (self.name)
-        return s + `self.line`
+        return s + repr(self.line)
 
     def isempty(self, ignore_comments=False):
         return not (self.line or self.label is not None or self.name is not None)
@@ -884,7 +886,7 @@ class FortranReaderBase(object):
         if m:
             newline = m.group('indent')+5*' '+m.group('rest')
             self.f2py_comment_lines.append(self.linecount)
-            assert len(newline)==len(line),`newlinel,line`
+            assert len(newline)==len(line), repr((newlinel,line))
             return newline
         return line
 
@@ -1288,7 +1290,7 @@ cf2py call me ! hey
     reader = FortranStringReader(string_f77)
     assert reader.mode=='fix77', `reader.mode`
     for item in reader:
-        print item
+        print (item)
 
     filename = tempfile.mktemp()+'.f'
     f = open(filename,'w')
@@ -1297,7 +1299,7 @@ cf2py call me ! hey
 
     reader = FortranFileReader(filename)
     for item in reader:
-        print item
+        print (item)
 
 def test_pyf():
     string_pyf = """! -*- pyf -*-
@@ -1330,7 +1332,7 @@ end python module foo
     reader = FortranStringReader(string_pyf)
     assert reader.mode=='pyf', `reader.mode`
     for item in reader:
-        print item
+        print (item)
 
 def test_fix90():
     string_fix90 = """c -*- fix -*-
@@ -1355,14 +1357,14 @@ cComment
     reader = FortranStringReader(string_fix90)
     assert reader.mode=='fix90', `reader.mode`
     for item in reader:
-        print item
+        print (item)
 
 def simple_main():
     for filename in sys.argv[1:]:
-        print 'Processing',filename
+        print ('Processing',filename)
         reader = FortranFileReader(filename)
         for item in reader:
-            print >> sys.stdout, item
+            print (item, file = sys.stdout)
             sys.stdout.flush()
             pass
 
diff --git a/src/fparser/splitline.py b/src/fparser/splitline.py
index 5b8e7e6..9849aa1 100644
--- a/src/fparser/splitline.py
+++ b/src/fparser/splitline.py
@@ -72,6 +72,8 @@ First version created: May 2006
 -----
 """
 
+from __future__ import print_function
+
 __all__ = ['String','string_replace_map','splitquote','splitparen']
 
 import re
@@ -443,18 +445,18 @@ class LineSplitterParen(LineSplitterBase):
 def test():
     splitter = LineSplitter('abc\\\' def"12\\"3""56"dfad\'a d\'')
     l = [item for item in splitter]
-    assert l==['abc\\\' def','"12\\"3"','"56"','dfad','\'a d\''],`l`
+    assert l==['abc\\\' def','"12\\"3"','"56"','dfad','\'a d\''],repr(l)
     assert splitter.quotechar is None
     l,stopchar=splitquote('abc\\\' def"12\\"3""56"dfad\'a d\'')
-    assert l==['abc\\\' def','"12\\"3"','"56"','dfad','\'a d\''],`l`
+    assert l==['abc\\\' def','"12\\"3"','"56"','dfad','\'a d\''],repr(l)
     assert stopchar is None
 
     splitter = LineSplitter('"abc123&')
     l = [item for item in splitter]
-    assert l==['"abc123&'],`l`
+    assert l==['"abc123&'],repr(l)
     assert splitter.quotechar=='"'
     l,stopchar = splitquote('"abc123&')
-    assert l==['"abc123&'],`l`
+    assert l==['"abc123&'],repr(l)
     assert stopchar=='"'
 
     splitter = LineSplitter(' &abc"123','"')
@@ -466,23 +468,23 @@ def test():
     assert stopchar is None
 
     l = split2('')
-    assert l==('',''),`l`
+    assert l==('',''),repr(l)
     l = split2('12')
-    assert l==('12',''),`l`
+    assert l==('12',''),repr(l)
     l = split2('1"a"//"b"')
-    assert l==('1','"a"//"b"'),`l`
+    assert l==('1','"a"//"b"'),repr(l)
     l = split2('"ab"')
-    assert l==('','"ab"'),`l`
+    assert l==('','"ab"'),repr(l)
 
     splitter = LineSplitterParen('a(b) = b(x,y(1)) b\((a)\)')
     l = [item for item in splitter]
-    assert l==['a', '(b)', ' = b', '(x,y(1))', ' b\\(', '(a)', '\\)'],`l`
+    assert l==['a', '(b)', ' = b', '(x,y(1))', ' b\\(', '(a)', '\\)'],repr(l)
     l = splitparen('a(b) = b(x,y(1)) b\((a)\)')
-    assert l==['a', '(b)', ' = b', '(x,y(1))', ' b\\(', '(a)', '\\)'],`l`
+    assert l==['a', '(b)', ' = b', '(x,y(1))', ' b\\(', '(a)', '\\)'],repr(l)
 
     l = string_replace_map('a()')
-    print l
-    print 'ok'
+    print (l)
+    print ('ok')
 
 if __name__ == '__main__':
     test()
diff --git a/src/fparser/statements.py b/src/fparser/statements.py
index 6d9b350..bda5a95 100644
--- a/src/fparser/statements.py
+++ b/src/fparser/statements.py
@@ -66,6 +66,7 @@
 Fortran single line statements.
 
 """
+from __future__ import print_function
 
 __all__ = ['GeneralAssignment',
            'Assignment','PointerAssignment','Assign','Call','Goto','ComputedGoto','AssignedGoto',
@@ -85,14 +86,14 @@ __all__ = ['GeneralAssignment',
 import re
 import sys
 
-from base_classes import Statement, Variable
+from .base_classes import Statement, Variable
 
 # Auxiliary tools
 
-from utils import split_comma, specs_split_comma, AnalyzeError, ParseError, \
+from .utils import split_comma, specs_split_comma, AnalyzeError, ParseError, \
      get_module_file, parse_bind, parse_result, is_name, \
      extract_bracketed_list_items
-from utils import classes
+from .utils import classes
 
 class StatementWithNamelist(Statement):
     """
@@ -288,7 +289,7 @@ class Call(Statement):
         if hasattr(a, 'external'):
             external = a.external
             if self.designator in external:
-                print >> sys.stderr, 'Need to analyze:',self
+                print ('Need to analyze:' + self, file=sys.stderr)
         return
 
 class Goto(Statement):
@@ -340,7 +341,7 @@ class AssignedGoto(Statement):
             self.items = []
             return
         self.varname = line[:i].rstrip()
-        assert line[-1]==')',`line`
+        assert line[-1]==')',repr(line)
         self
         self.items = split_comma(line[i+1:-1], self.item)
         return
@@ -497,7 +498,7 @@ class Write(Statement):
         item = self.item
         line = item.get_line()[5:].lstrip()
         i = line.find(')')
-        assert i != -1, `line`
+        assert i != -1, repr(line)
         self.specs = specs_split_comma(line[1:i], item)
         self.items = split_comma(line[i+1:], item)
         return
@@ -527,7 +528,7 @@ class Flush(Statement):
             self.isvalid = False
             return
         if line.startswith('('):
-            assert line[-1] == ')', `line`
+            assert line[-1] == ')', repr(line)
             self.specs = specs_split_comma(line[1:-1],self.item)
         else:
             self.specs = specs_split_comma(line,self.item)
@@ -584,7 +585,7 @@ class Allocate(Statement):
         i = line2.find('::')
         if i != -1:
             spec = item2.apply_map(line2[:i].rstrip())
-            from block_statements import type_spec
+            from .block_statements import type_spec
             stmt = None
             for cls in type_spec:
                 if cls.match(spec):
@@ -594,7 +595,7 @@ class Allocate(Statement):
             if stmt is not None and stmt.isvalid:
                 spec = stmt
             else:
-                self.warning('TODO: unparsed type-spec' + `spec`)
+                self.warning('TODO: unparsed type-spec' + repr(spec))
             line2 = line2[i+2:].lstrip()
         else:
             spec = None
@@ -636,7 +637,7 @@ class ModuleProcedure(Statement):
     def process_item(self):
         line = self.item.get_line()
         m = self.match(line)
-        assert m,`line`
+        assert m,repr(line)
         items = split_comma(line[m.end():].strip(), self.item)
         for n in items:
             if not is_name(n):
@@ -764,7 +765,7 @@ class FilePositioningStatement(Statement):
             return
         line = line[len(clsname):].lstrip()
         if line.startswith('('):
-            assert line[-1]==')',`line`
+            assert line[-1]==')',repr(line)
             spec = line[1:-1].strip()
         else:
             spec = line
@@ -830,7 +831,7 @@ class Format(Statement):
             self.warning('FORMAT statement must be labeled (F2008:C1001).' \
                          % (item.label))
         line = item.get_line()[6:].lstrip()
-        assert line[0]+line[-1]=='()',`line`
+        assert line[0]+line[-1]=='()',repr(line)
         self.specs = split_comma(line[1:-1], item)
         return
     def tofortran(self, isfix=None):
@@ -857,9 +858,9 @@ class Save(Statement):
             s = s.strip()
             if not s: continue
             if s.startswith('/'):
-                assert s.endswith('/'),`s`
+                assert s.endswith('/'),repr(s)
                 n = s[1:-1].strip()
-                assert is_name(n),`n`
+                assert is_name(n),repr(n)
                 items.append('/%s/' % (n))
             elif is_name(s):
                 items.append(s)
@@ -998,8 +999,8 @@ class Use(Statement):
         if self.name not in modules:
             fn = self.reader.find_module_source_file(self.name)
             if fn is not None:
-                from readfortran import FortranFileReader
-                from parsefortran import FortranParser
+                from .readfortran import FortranFileReader
+                from .parsefortran import FortranParser
                 self.info('looking module information from %r' % (fn))
                 reader = FortranFileReader(fn, include_dirs=self.reader.include_dirs, source_only=self.reader.source_only)
                 parser = FortranParser(reader)
@@ -1082,7 +1083,7 @@ class Parameter(Statement):
     def analyze(self):
         for item in self.items:
             i = item.find('=')
-            assert i!=-1,`item`
+            assert i!=-1,repr(item)
             name = item[:i].rstrip()
             value = item[i+1:].lstrip()
             var = self.get_variable(name)
@@ -1101,7 +1102,7 @@ class Equivalence(Statement):
         items = []
         for s in self.item.get_line()[11:].lstrip().split(','):
             s = s.strip()
-            assert s[0]+s[-1]=='()',`s,self.item.get_line()`
+            assert s[0]+s[-1]=='()',repr((s,self.item.get_line()))
             s = ', '.join(split_comma(s[1:-1], self.item))
             items.append('('+s+')')
         self.items = items
@@ -1127,7 +1128,7 @@ class Dimension(Statement):
     def analyze(self):
         for line in self.items:
             i = line.find('(')
-            assert i!=-1 and line.endswith(')'),`line`
+            assert i!=-1 and line.endswith(')'),repr(line)
             name = line[:i].rstrip()
             array_spec = split_comma(line[i+1:-1].strip(), self.item)
             var = self.get_variable(name)
@@ -1151,7 +1152,7 @@ class Target(Statement):
     def analyze(self):
         for line in self.items:
             i = line.find('(')
-            assert i!=-1 and line.endswith(')'),`line`
+            assert i!=-1 and line.endswith(')'),repr(line)
             name = line[:i].rstrip()
             array_spec = split_comma(line[i+1:-1].strip(), self.item)
             var = self.get_variable(name)
@@ -1183,7 +1184,7 @@ class Pointer(Statement):
                 name = line
                 array_spec = None
             else:
-                assert line.endswith(')'),`line`
+                assert line.endswith(')'),repr(line)
                 name = line[:i].rstrip()
                 array_spec = split_comma(line[i+1:-1].strip(), self.item)
             var = self.get_variable(name)
@@ -1314,9 +1315,9 @@ class Namelist(Statement):
         line = self.item.get_line()[8:].lstrip()
         items = []
         while line:
-            assert line.startswith('/'),`line`
+            assert line.startswith('/'),repr(line)
             i = line.find('/',1)
-            assert i!=-1,`line`
+            assert i!=-1,repr(line)
             name = line[:i+1]
             line = line[i+1:].lstrip()
             i = line.find('/')
@@ -1354,10 +1355,10 @@ class Common(Statement):
         while line:
             if not line.startswith('/'):
                 name = ''
-                assert not items,`line`
+                assert not items,repr(line)
             else:
                 i = line.find('/',1)
-                assert i!=-1,`line`
+                assert i!=-1,repr(line)
                 name = line[1:i].strip()
                 line = line[i+1:].lstrip()
             i = line.find('/')
@@ -1387,7 +1388,7 @@ class Common(Statement):
             for item in items:
                 i = item.find('(')
                 if i!=-1:
-                    assert item.endswith(')'),`item`
+                    assert item.endswith(')'),repr(item)
                     name = item[:i].rstrip()
                     shape = split_comma(item[i+1:-1].strip(), self.item)
                 else:
@@ -1461,7 +1462,7 @@ class Entry(Statement):
         line = line[m.end():].lstrip()
         if line.startswith('('):
             i = line.find(')')
-            assert i!=-1,`line`
+            assert i!=-1,repr(line)
             items = split_comma(line[1:i], self.item)
             line = line[i+1:].lstrip()
         else:
@@ -1469,9 +1470,9 @@ class Entry(Statement):
         self.bind, line = parse_bind(line, self.item)
         self.result, line = parse_result(line, self.item)
         if line:
-            assert self.bind is None,`self.bind`
+            assert self.bind is None,repr(self.bind)
             self.bind, line = parse_bind(line, self.item)
-        assert not line,`line`
+        assert not line,repr(line)
         self.name = name
         self.items = items
         return
@@ -1519,10 +1520,10 @@ class Forall(Statement):
         for l in split_comma(line0,self.item):
             j = l.find('=')
             if j==-1:
-                assert not mask,`mask,l`
+                assert not mask,repr((mask,l))
                 mask = l
                 continue
-            assert j!=-1,`l`
+            assert j!=-1,repr(l)
             index = l[:j].rstrip()
             it = self.item.copy(l[j+1:].lstrip())
             l = it.get_line()
@@ -1531,7 +1532,7 @@ class Forall(Statement):
                 s1, s2, s3 = map(it.apply_map,
                                  [k[0].strip(),k[1].strip(),k[2].strip()])
             else:
-                assert len(k)==2,`k`
+                assert len(k)==2,repr(k)
                 s1, s2 = map(it.apply_map,
                              [k[0].strip(),k[1].strip()])
                 s3 = '1'
@@ -1592,7 +1593,7 @@ class SpecificBinding(Statement):
                 attr = attr.upper()
             else:
                 i = attr.find('(')
-                assert i!=-1 and attr.endswith(')'),`attr`
+                assert i!=-1 and attr.endswith(')'),repr(attr)
                 attr = '%s (%s)' % (attr[:i].rstrip().upper(), attr[i+1:-1].strip())
             attrs1.append(attr)
         self.attrs = attrs1
@@ -1706,7 +1707,7 @@ class Bind(Statement):
         items = []
         for item in split_comma(line, self.item):
             if item.startswith('/'):
-                assert item.endswith('/'),`item`
+                assert item.endswith('/'),repr(item)
                 item = '/ ' + item[1:-1].strip() + ' /'
             items.append(item)
         self.items = items
@@ -1980,7 +1981,7 @@ class ElseWhere(Statement):
         self.expr = None
         if line.startswith('('):
             i = line.index(')')
-            assert i != -1,`line`
+            assert i != -1,repr(line)
             self.expr = self.item.apply_map(line[1:i].strip())
             line = line[i+1:].lstrip()
         self.name = line
@@ -2070,7 +2071,7 @@ class Check(Statement):
     def process_item(self):
         line = self.item.get_line()[5:].lstrip()
         i = line.find(')')
-        assert i!=-1,`line`
+        assert i!=-1,repr(line)
         self.expr = self.item.apply_map(line[1:i].strip())
         line = line[i+1:].lstrip()
         if line.startswith('::'):
@@ -2131,7 +2132,7 @@ class Comment(Statement):
     """
     match = lambda s: True
     def process_item(self):
-        assert self.item.comment.count('\n')<=1,`self.item`
+        assert self.item.comment.count('\n')<=1,repr(self.item)
         stripped = self.item.comment.lstrip()
         self.is_blank = not stripped
         self.content = stripped[1:] if stripped else ''
diff --git a/src/fparser/tests/test_api.py b/src/fparser/tests/test_api.py
index 8dca41d..55788ef 100644
--- a/src/fparser/tests/test_api.py
+++ b/src/fparser/tests/test_api.py
@@ -65,6 +65,7 @@
 """
 Test parsing of whole fortran files; 'blackbox' tests here.
 """
+from __future__ import print_function
 
 from fparser import api
 import sys
@@ -175,4 +176,4 @@ def test_walk():
     '''
     tree = api.parse(source_str, isfree=True, isstrict=False, ignore_comments=False)
     for stmt, depth in api.walk(tree, 1):
-        print depth, stmt.item
+        print (depth, stmt.item)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/fparser.git



More information about the Python-modules-commits mailing list