summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-05 07:22:05 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-05 07:22:05 (GMT)
commit3eb554fc828c812a31c1a3cd9f619eacbb708010 (patch)
tree8f949a481d0170358d6d06ea577d0ce766383d15 /Tools/scripts
parent423f1282b3476e2e58b6631632f2521b80f556c7 (diff)
downloadcpython-3eb554fc828c812a31c1a3cd9f619eacbb708010.zip
cpython-3eb554fc828c812a31c1a3cd9f619eacbb708010.tar.gz
cpython-3eb554fc828c812a31c1a3cd9f619eacbb708010.tar.bz2
Issue #22221: Backported fixes from Python 3 (issue #18960).
* Now the source encoding declaration on the second line isn't effective if the first line contains anything except a comment. This affects compile(), eval() and exec() too. * IDLE now ignores the source encoding declaration on the second line if the first line contains anything except a comment. * 2to3 and the findnocoding.py script now ignore the source encoding declaration on the second line if the first line contains anything except a comment.
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-xTools/scripts/findnocoding.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Tools/scripts/findnocoding.py b/Tools/scripts/findnocoding.py
index 5d93290..70b1a66 100755
--- a/Tools/scripts/findnocoding.py
+++ b/Tools/scripts/findnocoding.py
@@ -33,6 +33,7 @@ except ImportError:
decl_re = re.compile(r'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)')
+blank_re = re.compile(r'^[ \t\f]*(?:[#\r\n]|$)')
def get_declaration(line):
match = decl_re.match(line)
@@ -57,7 +58,8 @@ def needs_declaration(fullpath):
line1 = infile.readline()
line2 = infile.readline()
- if get_declaration(line1) or get_declaration(line2):
+ if (get_declaration(line1) or
+ blank_re.match(line1) and get_declaration(line2)):
# the file does have an encoding declaration, so trust it
infile.close()
return False