File tree 4 files changed +36
-28
lines changed
4 files changed +36
-28
lines changed Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ def check_global_args(args):
125
125
is_socket = stat .S_ISSOCK (mode )
126
126
if not is_socket :
127
127
logging .fatal (
128
- 'Invalid MySQL socket. Use --mysql-socket options.' .format (args .mysql_socket )
128
+ 'Invalid MySQL socket: {0} . Use --mysql-socket options.' .format (args .mysql_socket )
129
129
)
130
130
sys .exit (1 )
131
131
Original file line number Diff line number Diff line change 30
30
except ImportError :
31
31
from configparser import ConfigParser
32
32
33
+ try :
34
+ stringTypes = (str , unicode )
35
+ except TypeError :
36
+ stringTypes = (str ,)
37
+
33
38
import MySQLdb as sql
34
39
35
40
@@ -59,25 +64,26 @@ def dbparam(x):
59
64
elif isinstance (x , ColumnName ):
60
65
return "`" + x + "`"
61
66
elif isinstance (x , bytes ):
62
- return "'" + str (x ) + "'"
63
- elif isinstance (x , str ):
67
+ return "'" + str (x . decode () ) + "'"
68
+ elif isinstance (x , stringTypes ):
64
69
return "'" + x + "'"
65
70
else :
66
71
return repr (x )
67
72
68
73
69
74
def _parseMyCnf (my_cnf ):
70
75
parser = ConfigParser ()
71
- parser .read_file (open (my_cnf ), my_cnf )
72
- kw = {}
73
- for section in parser .sections ():
74
- for key , val in parser [section ].items ():
75
- if key == 'user' :
76
- kw ['user' ] = val
77
- elif key == 'password' :
78
- kw ['passwd' ] = val
79
- elif key == 'socket' :
80
- kw ['unix_socket' ] = val
76
+ with open (my_cnf ) as conf_file :
77
+ parser .read_file (conf_file , my_cnf )
78
+ kw = {}
79
+ for section in parser .sections ():
80
+ for key , val in parser [section ].items ():
81
+ if key == 'user' :
82
+ kw ['user' ] = val
83
+ elif key == 'password' :
84
+ kw ['passwd' ] = val
85
+ elif key == 'socket' :
86
+ kw ['unix_socket' ] = val
81
87
return kw
82
88
83
89
Original file line number Diff line number Diff line change @@ -347,8 +347,8 @@ def extract_docs_from_c(filename):
347
347
elt = etree .XML (xml )
348
348
docs .append (ast (elt ))
349
349
except :
350
- sys . stderr . write ("Failed to parse documentation block:\n \n %s\n \n " % xml )
351
- sys . stderr . write (traceback .format_exc ())
350
+ print ("Failed to parse documentation block:\n \n %s\n \n " % xml , file = sys . stderr )
351
+ print (traceback .format_exc (), file = sys . stderr )
352
352
return docs
353
353
354
354
@@ -372,8 +372,8 @@ def extract_docs_from_sql(filename):
372
372
elt = etree .XML (string .Template (xml ).safe_substitute (os .environ ))
373
373
docs .append (ast (elt ))
374
374
except ValueError :
375
- sys . stderr . write ("Failed to parse documentation block:\n \n %s\n \n " % xml )
376
- sys . stderr . write (traceback .format_exc ())
375
+ print ("Failed to parse documentation block:\n \n %s\n \n " % xml , file = sys . stderr )
376
+ print (traceback .format_exc (), file = sys . stderr )
377
377
return docs
378
378
379
379
@@ -425,7 +425,8 @@ def _test(obj):
425
425
with open (os .devnull , 'wb' ) as devnull :
426
426
subprocess .check_call (args , shell = False , stdin = source , stdout = devnull )
427
427
except subprocess .CalledProcessError :
428
- sys .stderr .write ("Failed to run documentation example:\n \n %s\n \n " % ex .source )
428
+ print ("Failed to run documentation example:\n \n %s\n \n " % ex .source ,
429
+ file = sys .stderr )
429
430
nfail += 1
430
431
return nfail
431
432
Original file line number Diff line number Diff line change 67
67
68
68
def _parseMyCnf (my_cnf ):
69
69
parser = ConfigParser ()
70
- parser .read_file (open (my_cnf ), my_cnf )
71
- kw = {}
72
- for section in parser .sections ():
73
- for key , val in parser [section ].items ():
74
- if key == 'user' :
75
- kw ['user' ] = val
76
- elif key == 'password' :
77
- kw ['passwd' ] = val
78
- elif key == 'socket' :
79
- kw ['unix_socket' ] = val
70
+ with open (my_cnf ) as conf_file :
71
+ parser .read_file (conf_file , my_cnf )
72
+ kw = {}
73
+ for section in parser .sections ():
74
+ for key , val in parser [section ].items ():
75
+ if key == 'user' :
76
+ kw ['user' ] = val
77
+ elif key == 'password' :
78
+ kw ['passwd' ] = val
79
+ elif key == 'socket' :
80
+ kw ['unix_socket' ] = val
80
81
return kw
81
82
82
83
You can’t perform that action at this time.
0 commit comments