Issue #18873: The tokenize module, IDLE, 2to3, and the findnocoding.py script

now detect Python source code encoding only in comment lines.
This commit is contained in:
Serhiy Storchaka 2013-09-16 23:51:56 +03:00
parent 975fce3788
commit dafea85190
9 changed files with 44 additions and 22 deletions

View file

@ -32,13 +32,13 @@ except ImportError:
"no sophisticated Python source file search will be done.", file=sys.stderr)
decl_re = re.compile(rb"coding[=:]\s*([-\w.]+)")
decl_re = re.compile(rb'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)')
def get_declaration(line):
match = decl_re.search(line)
match = decl_re.match(line)
if match:
return match.group(1)
return ''
return b''
def has_correct_encoding(text, codec):
try: