Skip to content
Myr

Don't scan the whole file contents for template detection

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 17d1ade · Browse files · 1 file+9 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−11 removed

  • other:+9 added−11 removed

1 file+9 added−11 removed

modified:scripts/flask-07-upgrade.py+9 added-11 removed
31 unmodified lines
32except ImportError:33 ast = None343536TEMPLATE_LOOKAHEAD = 4096373839_from_import_re = re.compile(r'^\s*from flask import\s+')40_string_re_part = r"('([^'\\]*(?:\\.[^'\\]*)*)'" \41 r'|"([^"\\]*(?:\\.[^"\\]*)*)")'42_url_for_re = re.compile(r'\b(url_for\()(%s)' % _string_re_part)
9 unmodified lines
52 (re.compile(r'(app|application)\.modules'), '\\1.blueprints')53]545553def error(message):54 print >> sys.stderr, 'error:', message55 sys.exit(1)565756def make_diff(filename, old, new):57 for line in difflib.unified_diff(old.splitlines(), new.splitlines(),58 posixpath.normpath(posixpath.join('a', filename)),59 posixpath.normpath(posixpath.join('b', filename)),
190 unmodified lines
250 if filename.endswith('.py'):251 yield filename, 'python'252 else:253 with open(filename) as f:256 contents = f.read()254 contents = f.read(TEMPLATE_LOOKAHEAD)255 if '{% for' or '{% if' or '{{ url_for' in contents:256 yield filename, 'template'257258
24 unmodified lines
283284285def main():286 """Entrypoint"""289 if ast is None:290 error('Python 2.6 or later is required to run the upgrade script.\n'291 'The runtime requirements for Flask 0.7 however are still '292 'Python 2.5.')293287 parser = OptionParser()288 parser.add_option('-T', '--no-teardown-detection', dest='no_teardown',289 action='store_true', help='Do not attempt to '290 'detect teardown function rewrites.')
8 unmodified lines
299 options, args = parser.parse_args()300 if not args:301 args = ['.']302303 if ast is None:304 parser.error('Python 2.6 or later is required to run the upgrade script.\n'305 'The runtime requirements for Flask 0.7 however are still '306 'Python 2.5.')307308 if options.no_bundled_tmpl:309 template_bundles = False310 elif options.bundled_tmpl:311 template_bundles = True
10 unmodified lines