Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15189)

Unified Diff: Lib/idlelib/IOBinding.py

Issue 18873: "Encoding" detected in non-comment lines
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/lib2to3/pgen2/tokenize.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/idlelib/IOBinding.py Thu Sep 05 18:02:31 2013 +0300
+++ b/Lib/idlelib/IOBinding.py Sat Sep 07 17:49:25 2013 +0300
@@ -63,7 +63,7 @@
encoding = locale_encoding ### KBK 07Sep07 This is used all over IDLE, check!
### 'encoding' is used below in encode(), check!
-coding_re = re.compile("coding[:=]\s*([-\w_.]+)")
+coding_re = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)', re.ASCII)
def coding_spec(data):
"""Return the encoding declaration according to PEP 263.
@@ -84,14 +84,16 @@
lines = data
# consider only the first two lines
if '\n' in lines:
- lst = lines.split('\n')[:2]
+ lst = lines.split('\n', 2)[:2]
elif '\r' in lines:
- lst = lines.split('\r')[:2]
+ lst = lines.split('\r', 2)[:2]
else:
- lst = list(lines)
- str = '\n'.join(lst)
- match = coding_re.search(str)
- if not match:
+ lst = [lines]
+ for line in lst:
+ match = coding_re.match(line)
+ if match is not None:
+ break
+ else:
return None
name = match.group(1)
try:
« no previous file with comments | « no previous file | Lib/lib2to3/pgen2/tokenize.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+