summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-03-20 21:36:29 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-03-20 21:36:29 (GMT)
commit6d297cbec48e9026ddf31d2ff95df7c182572dc9 (patch)
tree77e0dd82cbcfa6c48fffeeb24f6c31ec62510bfa
parentcac1d236a24e2755c05103d485a3b42a884b5a45 (diff)
downloadcpython-6d297cbec48e9026ddf31d2ff95df7c182572dc9.zip
cpython-6d297cbec48e9026ddf31d2ff95df7c182572dc9.tar.gz
cpython-6d297cbec48e9026ddf31d2ff95df7c182572dc9.tar.bz2
Issue #26581: Use the first coding cookie on a line, not the last one.
-rw-r--r--Lib/idlelib/IOBinding.py2
-rw-r--r--Lib/lib2to3/pgen2/tokenize.py2
-rw-r--r--Misc/NEWS3
-rwxr-xr-xTools/scripts/findnocoding.py2
4 files changed, 6 insertions, 3 deletions
diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py
index ef40715..1233d80 100644
--- a/Lib/idlelib/IOBinding.py
+++ b/Lib/idlelib/IOBinding.py
@@ -65,7 +65,7 @@ else:
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]|$)')
class EncodingMessage(SimpleDialog):
diff --git a/Lib/lib2to3/pgen2/tokenize.py b/Lib/lib2to3/pgen2/tokenize.py
index d64a3e6..8cae873 100644
--- a/Lib/lib2to3/pgen2/tokenize.py
+++ b/Lib/lib2to3/pgen2/tokenize.py
@@ -236,7 +236,7 @@ class Untokenizer:
startline = False
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]|$)')
def _get_normal_name(orig_enc):
diff --git a/Misc/NEWS b/Misc/NEWS
index 56e2cad..3f6ae5d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 2.7.12?
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
PyErr_WriteUnraisable() are sensible even when formatting them produces
secondary errors. This affects the reports produced by
diff --git a/Tools/scripts/findnocoding.py b/Tools/scripts/findnocoding.py
index 70b1a66..79ea7e5 100755
--- a/Tools/scripts/findnocoding.py
+++ b/Tools/scripts/findnocoding.py
@@ -32,7 +32,7 @@ except ImportError:
"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]|$)')
def get_declaration(line):