Author: Amaury Forgeot d'Arc <amaur...@gmail.com>
Branch: stdlib-2.7.9
Changeset: r75750:84cced3cc507
Date: 2015-02-07 10:34 +0100
http://bitbucket.org/pypy/pypy/changeset/84cced3cc507/

Log:    "coding:utf8" cookie: Don't read the second line if the first is not
        a comment.

diff --git a/pypy/interpreter/pyparser/pyparse.py 
b/pypy/interpreter/pyparser/pyparse.py
--- a/pypy/interpreter/pyparser/pyparse.py
+++ b/pypy/interpreter/pyparser/pyparse.py
@@ -34,14 +34,14 @@
 def _check_for_encoding(s):
     eol = s.find('\n')
     if eol < 0:
-        return _check_line_for_encoding(s)
-    enc = _check_line_for_encoding(s[:eol])
-    if enc:
+        return _check_line_for_encoding(s)[0]
+    enc, again = _check_line_for_encoding(s[:eol])
+    if enc or not again:
         return enc
     eol2 = s.find('\n', eol + 1)
     if eol2 < 0:
-        return _check_line_for_encoding(s[eol + 1:])
-    return _check_line_for_encoding(s[eol + 1:eol2])
+        return _check_line_for_encoding(s[eol + 1:])[0]
+    return _check_line_for_encoding(s[eol + 1:eol2])[0]
 
 
 def _check_line_for_encoding(line):
@@ -51,8 +51,8 @@
         if line[i] == '#':
             break
         if line[i] not in ' \t\014':
-            return None
-    return pytokenizer.match_encoding_declaration(line[i:])
+            return None, False  # Not a comment, don't read the second line.
+    return pytokenizer.match_encoding_declaration(line[i:]), True
 
 
 class CompileInfo(object):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to