diff options
Diffstat (limited to 'numpy/linalg/lapack_lite/clapack_scrub.py')
-rw-r--r-- | numpy/linalg/lapack_lite/clapack_scrub.py | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/numpy/linalg/lapack_lite/clapack_scrub.py b/numpy/linalg/lapack_lite/clapack_scrub.py index 738fad7fe..fffd70910 100644 --- a/numpy/linalg/lapack_lite/clapack_scrub.py +++ b/numpy/linalg/lapack_lite/clapack_scrub.py @@ -1,12 +1,17 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python2.7 +# WARNING! This a Python 2 script. Read README.rst for rationale. import os import re import sys -from io import StringIO from plex import Scanner, Str, Lexicon, Opt, Bol, State, AnyChar, TEXT, IGNORE from plex.traditional import re as Re +try: + from io import BytesIO as UStringIO # Python 2 +except ImportError: + from io import StringIO as UStringIO # Python 3 + class MyScanner(Scanner): def __init__(self, info, name='<default>'): @@ -22,8 +27,8 @@ def sep_seq(sequence, sep): return pat def runScanner(data, scanner_class, lexicon=None): - info = StringIO(data) - outfo = StringIO() + info = UStringIO(data) + outfo = UStringIO() if lexicon is not None: scanner = scanner_class(lexicon, info) else: @@ -190,7 +195,7 @@ def cleanComments(source): return SourceLines state = SourceLines - for line in StringIO(source): + for line in UStringIO(source): state = state(line) comments.flushTo(lines) return lines.getValue() @@ -218,20 +223,23 @@ def removeHeader(source): return OutOfHeader state = LookingForHeader - for line in StringIO(source): + for line in UStringIO(source): state = state(line) return lines.getValue() def removeSubroutinePrototypes(source): - expression = re.compile( - r'/\* Subroutine \*/^\s*(?:(?:inline|static)\s+){0,2}(?!else|typedef|return)\w+\s+\*?\s*(\w+)\s*\([^0]+\)\s*;?' - ) - lines = LineQueue() - for line in StringIO(source): - if not expression.match(line): - lines.add(line) - - return lines.getValue() + # This function has never worked as advertised by its name: + # - "/* Subroutine */" declarations may span multiple lines and + # cannot be matched by a line by line approach. + # - The caret in the initial regex would prevent any match, even + # of single line "/* Subroutine */" declarations. + # + # While we could "fix" this function to do what the name implies + # it should do, we have no hint of what it should really do. + # + # Therefore we keep the existing (non-)functionaity, documenting + # this function as doing nothing at all. + return source def removeBuiltinFunctions(source): lines = LineQueue() @@ -249,7 +257,7 @@ def removeBuiltinFunctions(source): return InBuiltInFunctions state = LookingForBuiltinFunctions - for line in StringIO(source): + for line in UStringIO(source): state = state(line) return lines.getValue() @@ -299,6 +307,5 @@ if __name__ == '__main__': source = scrub_source(source, nsteps, verbose=True) - writefo = open(outfilename, 'w') - writefo.write(source) - writefo.close() + with open(outfilename, 'w') as writefo: + writefo.write(source) |