diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-09-16 23:51:56 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-09-16 23:51:56 +0300 |
commit | 275c691bf116de51bd87f1ae27a3215fba4d93a2 (patch) | |
tree | 8ecd07ed2ace779d0797886d3f6cb464c058e16f /Lib/tokenize.py | |
parent | 4c7047cb5e11f8a8fe5ca427d8bcd40d65dfabb8 (diff) | |
download | cpython-275c691bf116de51bd87f1ae27a3215fba4d93a2.tar.gz |
Issue #18873: The tokenize module, IDLE, 2to3, and the findnocoding.py script
now detect Python source code encoding only in comment lines.
Diffstat (limited to 'Lib/tokenize.py')
-rw-r--r-- | Lib/tokenize.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/tokenize.py b/Lib/tokenize.py index cbf91ef222..f1e61d8ad5 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -31,7 +31,7 @@ from token import * from codecs import lookup, BOM_UTF8 import collections from io import TextIOWrapper -cookie_re = re.compile("coding[:=]\s*([-\w.]+)") +cookie_re = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)', re.ASCII) import token __all__ = token.__all__ + ["COMMENT", "tokenize", "detect_encoding", @@ -372,10 +372,10 @@ def detect_encoding(readline): msg = '{} for {!r}'.format(msg, filename) raise SyntaxError(msg) - matches = cookie_re.findall(line_string) - if not matches: + match = cookie_re.match(line_string) + if not match: return None - encoding = _get_normal_name(matches[0]) + encoding = _get_normal_name(match.group(1)) try: codec = lookup(encoding) except LookupError: |