diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-09-16 23:57:00 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-09-16 23:57:00 +0300 |
commit | 935349406aeb9d43fecea447f0309ce63ed3a406 (patch) | |
tree | 0c0cbc4c991840c4cb1e0cf835069fe571be7c03 /Lib/tokenize.py | |
parent | Issue #17003: Unified the size argument names in the io module with common (diff) | |
parent | Issue #18873: The tokenize module, IDLE, 2to3, and the findnocoding.py script (diff) | |
download | cpython-935349406aeb9d43fecea447f0309ce63ed3a406.tar.gz cpython-935349406aeb9d43fecea447f0309ce63ed3a406.tar.bz2 cpython-935349406aeb9d43fecea447f0309ce63ed3a406.zip |
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 2fbde0fa9b4..91f8e4785b9 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: |