22# -*- coding: utf-8 -*-
33
44
5- from __future__ import absolute_import , unicode_literals
5+ from __future__ import absolute_import
66
77import ast
8+ import io
89import os
910from pyflakes import checker , messages
1011import sys
@@ -33,8 +34,9 @@ def __init__(self, filename, lineno, col, message):
3334 try :
3435 super (PySyntaxError , self ).__init__ (filename , lineno )
3536 except Exception :
36- sys .stderr .write ("\n An exception occurred while processing file %s\n " +
37+ sys .stderr .write ("\n An exception occurred while processing file %s\n "
3738 "The file could contain syntax errors.\n \n " % filename )
39+ raise
3840
3941 self .message_args = (col , message )
4042
@@ -64,10 +66,10 @@ def check(codeString, filename, verbosity=1):
6466 # it.
6567 w = checker .Checker (tree , filename )
6668
67- lines = codeString .split ('\n ' )
69+ lines = codeString .split (b '\n ' )
6870 # honour pyflakes:ignore comments
6971 messages = [message for message in w .messages
70- if (lines [message .lineno - 1 ].find ('pyflakes:ignore' ) < 0 and lines [message .lineno - 1 ].find ('pyflakes: ignore' )) ]
72+ if (lines [message .lineno - 1 ].find (b 'pyflakes:ignore' ) < 0 and lines [message .lineno - 1 ].find (b 'pyflakes: ignore' ) < 0 ) ]
7173 # honour pyflakes:
7274
7375 messages .sort (key = lambda x : x .lineno )
@@ -77,6 +79,8 @@ def check(codeString, filename, verbosity=1):
7779 else :
7880 sys .stderr .write ('.' )
7981 sys .stderr .flush ()
82+ if verbosity > 1 :
83+ sys .stderr .write (" %s\n " % filename )
8084 return messages
8185
8286
@@ -90,7 +94,9 @@ def checkPath(filename, verbosity):
9094 sys .stderr .write ("\n %-78s " % filename )
9195 sys .stderr .flush ()
9296 try :
93- return check (open (filename , encoding = 'utf-8' ).read () + '\n ' , filename , verbosity )
97+ with io .open (filename , 'br' ) as f :
98+ text = f .read ()
99+ return check (text + b'\n ' , filename , verbosity )
94100 except IOError as msg :
95101 return ["%s: %s" % (filename , msg .args [1 ])]
96102 except TypeError :
0 commit comments