Kaydet (Commit) 6d297cbe authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #26581: Use the first coding cookie on a line, not the last one.

üst cac1d236
...@@ -65,7 +65,7 @@ else: ...@@ -65,7 +65,7 @@ else:
encoding = encoding.lower() encoding = encoding.lower()
coding_re = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)') coding_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)')
blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)') blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)')
class EncodingMessage(SimpleDialog): class EncodingMessage(SimpleDialog):
......
...@@ -236,7 +236,7 @@ class Untokenizer: ...@@ -236,7 +236,7 @@ class Untokenizer:
startline = False startline = False
toks_append(tokval) toks_append(tokval)
cookie_re = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)') cookie_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)')
blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)') blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)')
def _get_normal_name(orig_enc): def _get_normal_name(orig_enc):
......
...@@ -10,6 +10,9 @@ What's New in Python 2.7.12? ...@@ -10,6 +10,9 @@ What's New in Python 2.7.12?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #26581: If coding cookie is specified multiple times on a line in
Python source code file, only the first one is taken to account.
- Issue #22836: Ensure exception reports from PyErr_Display() and - Issue #22836: Ensure exception reports from PyErr_Display() and
PyErr_WriteUnraisable() are sensible even when formatting them produces PyErr_WriteUnraisable() are sensible even when formatting them produces
secondary errors. This affects the reports produced by secondary errors. This affects the reports produced by
......
...@@ -32,7 +32,7 @@ except ImportError: ...@@ -32,7 +32,7 @@ except ImportError:
"no sophisticated Python source file search will be done.") "no sophisticated Python source file search will be done.")
decl_re = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)') decl_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)')
blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)') blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)')
def get_declaration(line): def get_declaration(line):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment