Permalink
Browse files

Don't scan the whole file contents for template detection

  • Loading branch information...
1 parent 17d1ade commit aa863efd9294dcd8afef6e5fa590ae2f88cbb0a2 @mitsuhiko mitsuhiko committed Jun 5, 2011
Showing with 9 additions and 11 deletions.
  1. +9 −11 scripts/flask-07-upgrade.py
@@ -33,6 +33,9 @@
ast = None
+TEMPLATE_LOOKAHEAD = 4096
+
+
_from_import_re = re.compile(r'^\s*from flask import\s+')
_string_re_part = r"('([^'\\]*(?:\\.[^'\\]*)*)'" \
r'|"([^"\\]*(?:\\.[^"\\]*)*)")'
@@ -50,11 +53,6 @@
]
-def error(message):
- print >> sys.stderr, 'error:', message
- sys.exit(1)
-
-
def make_diff(filename, old, new):
for line in difflib.unified_diff(old.splitlines(), new.splitlines(),
posixpath.normpath(posixpath.join('a', filename)),
@@ -253,7 +251,7 @@ def walk_path(path):
yield filename, 'python'
else:
with open(filename) as f:
- contents = f.read()
+ contents = f.read(TEMPLATE_LOOKAHEAD)
if '{% for' or '{% if' or '{{ url_for' in contents:
yield filename, 'template'
@@ -286,11 +284,6 @@ def autodetect_template_bundles(paths):
def main():
"""Entrypoint"""
- if ast is None:
- error('Python 2.6 or later is required to run the upgrade script.\n'
- 'The runtime requirements for Flask 0.7 however are still '
- 'Python 2.5.')
-
parser = OptionParser()
parser.add_option('-T', '--no-teardown-detection', dest='no_teardown',
action='store_true', help='Do not attempt to '
@@ -307,6 +300,11 @@ def main():
if not args:
args = ['.']
+ if ast is None:
+ parser.error('Python 2.6 or later is required to run the upgrade script.\n'
+ 'The runtime requirements for Flask 0.7 however are still '
+ 'Python 2.5.')
+
if options.no_bundled_tmpl:
template_bundles = False
elif options.bundled_tmpl:

0 comments on commit aa863ef

Please sign in to comment.