]> granicus.if.org Git - python/commitdiff
Issue #26581: Use the first coding cookie on a line, not the last one.
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 20 Mar 2016 21:36:29 +0000 (23:36 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 20 Mar 2016 21:36:29 +0000 (23:36 +0200)
Lib/idlelib/IOBinding.py
Lib/lib2to3/pgen2/tokenize.py
Misc/NEWS
Tools/scripts/findnocoding.py

index ef40715d2254288ae2f6ae76a247bdde71cf20fe..1233d80a79da51b6deca25e19b0b21ccbcceaf06 100644 (file)
@@ -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):
index d64a3e63e42cf994260e993597966ce66c55c038..8cae87371d7e46afeb348c368be1a1f39720d8f3 100644 (file)
@@ -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):
index 56e2cade3f2c53d3b4258fca9bc5527ee2228d80..3f6ae5d1549e196e5965842d12732db507589098 100644 (file)
--- 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
index 70b1a666133e75490b7c73c76a8385cf92af8a88..79ea7e553425bbf48c1a3931127e3d96b40b2e27 100755 (executable)
@@ -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):