1
1
#!/usr/bin/env python
2
2
3
+ from __future__ import print_function
4
+
3
5
import argparse
4
6
import ast
5
7
import sys
6
8
9
+
7
10
version_info = (0 , 1 , 2 )
8
11
__version__ = '.' .join (map (str , version_info ))
9
12
13
+
10
14
def stringify (node ):
11
15
if isinstance (node , ast .Name ):
12
16
return node .id
@@ -61,9 +65,9 @@ def __init__(self, filename, *args, **kwargs):
61
65
def check_execute (self , node ):
62
66
if isinstance (node , ast .BinOp ):
63
67
if isinstance (node .op , ast .Mod ):
64
- return IllegalLine ('string interpolation of SQL query' , node , self .filename )
68
+ return IllegalLine ('String interpolation of SQL query' , node , self .filename )
65
69
elif isinstance (node .op , ast .Add ):
66
- return IllegalLine ('string concatenation of SQL query' , node , self .filename )
70
+ return IllegalLine ('String concatenation of SQL query' , node , self .filename )
67
71
elif isinstance (node , ast .Call ):
68
72
if isinstance (node .func , ast .Attribute ):
69
73
if node .func .attr == 'format' :
@@ -86,7 +90,7 @@ def visit_Call(self, node):
86
90
except IndexError :
87
91
pass
88
92
elif function_name .lower () == 'eval' :
89
- self .errors .append (IllegalLine ('eval() is just generally evil ' , node , self .filename ))
93
+ self .errors .append (IllegalLine ('eval() is generally dangerous ' , node , self .filename ))
90
94
self .generic_visit (node )
91
95
92
96
def visit (self , node ):
@@ -132,10 +136,10 @@ def main():
132
136
for fname in args .files :
133
137
these_errors = check (fname )
134
138
if these_errors :
135
- print '\n ' .join (str (e ) for e in these_errors )
139
+ print ( '\n ' .join (str (e ) for e in these_errors ) )
136
140
errors .extend (these_errors )
137
141
if errors :
138
- print '%d total errors' % len (errors )
142
+ print ( '%d total errors' % len (errors ), file = sys . stderr )
139
143
return 1
140
144
else :
141
145
return 0
0 commit comments