]> granicus.if.org Git - python/commitdiff
Cleanup findnocoding.py and pysource.py scripts (with infile/infile.close)
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 1 Aug 2012 22:05:41 +0000 (00:05 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 1 Aug 2012 22:05:41 +0000 (00:05 +0200)
Tools/scripts/findnocoding.py
Tools/scripts/pysource.py

index d6643860a2497229000327ed9b5b02eb5324c20f..b3e9dc7361091251bce9e9385b8a0668c89c17f0 100755 (executable)
@@ -60,7 +60,6 @@ def needs_declaration(fullpath):
 
         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
index 7348a68f21702b5c1b2ed44924d37741e42337dd..69e8e0df4ff0802fc31bfb829fdc83bb4907b92e 100755 (executable)
@@ -55,8 +55,8 @@ def looks_like_python(fullpath):
     if infile is None:
         return False
 
-    line = infile.readline()
-    infile.close()
+    with infile:
+        line = infile.readline()
 
     if binary_re.search(line):
         # file appears to be binary
@@ -76,8 +76,8 @@ def can_be_compiled(fullpath):
     if infile is None:
         return False
 
-    code = infile.read()
-    infile.close()
+    with infile:
+        code = infile.read()
 
     try:
         compile(code, fullpath, "exec")