summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/IOBinding.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-09-16 21:00:46 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-09-16 21:00:46 (GMT)
commite787bce79c016cf7b9e743a6230ceb8e97b4a938 (patch)
tree2b86121e69e169391770e3adace1e55c28805fc8 /Lib/idlelib/IOBinding.py
parent74213e4ee941e163ebdfa6b7d3d493ee68f6bb8d (diff)
downloadcpython-e787bce79c016cf7b9e743a6230ceb8e97b4a938.zip
cpython-e787bce79c016cf7b9e743a6230ceb8e97b4a938.tar.gz
cpython-e787bce79c016cf7b9e743a6230ceb8e97b4a938.tar.bz2
Issue #18873: IDLE, 2to3, and the findnocoding.py script now detect Python
source code encoding only in comment lines.
Diffstat (limited to 'Lib/idlelib/IOBinding.py')
-rw-r--r--Lib/idlelib/IOBinding.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py
index ba45ee8..f5665b9 100644
--- a/Lib/idlelib/IOBinding.py
+++ b/Lib/idlelib/IOBinding.py
@@ -71,7 +71,7 @@ else:
encoding = encoding.lower()
-coding_re = re.compile("coding[:=]\s*([-\w_.]+)")
+coding_re = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)', re.ASCII)
class EncodingMessage(SimpleDialog):
"Inform user that an encoding declaration is needed."
@@ -125,11 +125,12 @@ def coding_spec(str):
Raise LookupError if the encoding is declared but unknown.
"""
# Only consider the first two lines
- str = str.split("\n")[:2]
- str = "\n".join(str)
-
- match = coding_re.search(str)
- if not match:
+ str = str.split("\n", 2)[:2]
+ for line in lst:
+ match = coding_re.match(line)
+ if match is not None:
+ break
+ else:
return None
name = match.group(1)
# Check whether the encoding is known