summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/findnocoding.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-08-01 18:12:51 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-08-01 18:12:51 (GMT)
commit98516a6930acdd39f74c609817cbf19be6c4a7df (patch)
tree89a0cac4c60cb0414c644cb1cc8e52d6096b9e8b /Tools/scripts/findnocoding.py
parent7c7ea62e6c20ed3a91dbac1ea922141975d0100f (diff)
downloadcpython-98516a6930acdd39f74c609817cbf19be6c4a7df.zip
cpython-98516a6930acdd39f74c609817cbf19be6c4a7df.tar.gz
cpython-98516a6930acdd39f74c609817cbf19be6c4a7df.tar.bz2
Fix findnocoding.p and pysource.py scripts
I suppose that these scripts didn't work since Python 3.0.
Diffstat (limited to 'Tools/scripts/findnocoding.py')
-rwxr-xr-xTools/scripts/findnocoding.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/Tools/scripts/findnocoding.py b/Tools/scripts/findnocoding.py
index 5aa1feb..d664386 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.", file=sys.stderr)
-decl_re = re.compile(r"coding[=:]\s*([-\w.]+)")
+decl_re = re.compile(rb"coding[=:]\s*([-\w.]+)")
def get_declaration(line):
match = decl_re.search(line)
@@ -50,21 +50,21 @@ def has_correct_encoding(text, codec):
def needs_declaration(fullpath):
try:
- infile = open(fullpath)
+ infile = open(fullpath, 'rb')
except IOError: # Oops, the file was removed - ignore it
return None
- line1 = infile.readline()
- line2 = infile.readline()
+ with infile:
+ line1 = infile.readline()
+ line2 = infile.readline()
- if get_declaration(line1) or get_declaration(line2):
- # the file does have an encoding declaration, so trust it
- infile.close()
- return False
+ if get_declaration(line1) or get_declaration(line2):
+ # the file does have an encoding declaration, so trust it
+ infile.close()
+ return False
- # check the whole file for non utf-8 characters
- rest = infile.read()
- infile.close()
+ # check the whole file for non utf-8 characters
+ rest = infile.read()
if has_correct_encoding(line1+line2+rest, "utf-8"):
return False