Plugins/CheckerPlugins/Tabnanny/Tabnanny.py

changeset 45
9a18f4dbb493
parent 15
f6ccc31d6e72
child 96
9624a110667d
--- a/Plugins/CheckerPlugins/Tabnanny/Tabnanny.py	Sun Jan 10 13:59:15 2010 +0000
+++ b/Plugins/CheckerPlugins/Tabnanny/Tabnanny.py	Sun Jan 10 19:19:52 2010 +0000
@@ -106,14 +106,9 @@
     check_equal = 0
 
     try:
-        f = open(file, "r")
-    except IOError as msg:
-        return (True, file, "1", "I/O Error: %s" % str(msg))
-
-    try:
-        text = f.read()
-    finally:
-        f.close()
+        text = Utilities.readEncodedFile(file)[0]
+    except (UnicodeError, IOError) as msg:
+        return (True, file, "1", "Error: %s" % str(msg))
         
     # convert eols
     text = Utilities.convertLineEnds(text, os.linesep)
@@ -123,24 +118,19 @@
         process_tokens(tokenize.generate_tokens(source.readline))
     
     except tokenize.TokenError as msg:
-        f.close()
         return (True, file, "1", "Token Error: %s" % str(msg))
     
     except IndentationError as err:
-        f.close()
         return (True, file, err.lineno, "Indentation Error: %s" % str(err.msg))
     
     except NannyNag as nag:
         badline = nag.get_lineno()
         line = nag.get_line()
-        f.close()
         return (True, file, str(badline), line)
     
     except Exception as err:
-        f.close()
         return (True, file, "1", "Unspecific Error: %s" % str(err))
     
-    f.close()
     return (False, None, None, None)
 
 class Whitespace(object):
@@ -400,4 +390,4 @@
             if not indents[-1].equal(thisguy):
                 witness = indents[-1].not_equal_witness(thisguy)
                 msg = "indent not equal e.g. " + format_witnesses(witness)
-                raise NannyNag(start[0], msg, line)
\ No newline at end of file
+                raise NannyNag(start[0], msg, line)

eric ide

mercurial