@@ -6,10 +6,11 @@ This is all very ordinary. We import the package bits, open and read
66a file, translate it, and write it out.
77
88"""
9+ import os .path
910import sys
1011from argparse import ArgumentParser , ArgumentTypeError
1112from collections import defaultdict
12- from logging import _levelNames as logLevels , exception , warning , info , basicConfig
13+ from logging import _nameToLevel as logLevels , exception , warning , info , basicConfig
1314from os import path , makedirs
1415from time import time
1516
@@ -60,8 +61,8 @@ def runOneOrMany(options):
6061 """ Runs our main transformer with each of the input files. """
6162 infile , outfile = options .inputfile , options .outputfile
6263
63- if infile and not isinstance (infile , file ) and path .isdir (infile ):
64- if outfile and not isinstance (outfile , file ) and not path .isdir (outfile ):
64+ if infile and not os . path . isfile (infile ) and path .isdir (infile ):
65+ if outfile and not os . path . isfile (outfile ) and not path .isdir (outfile ):
6566 warning ('Must specify output directory or stdout when using input directory.' )
6667 return 2
6768 def walker (arg , dirname , files ):
@@ -89,9 +90,9 @@ def runTransform(options):
8990 timed ['overall' ]
9091
9192 filein = fileout = filedefault = '-'
92- if options .inputfile and not isinstance (options .inputfile , file ):
93+ if options .inputfile and not os . path . isfile (options .inputfile ):
9394 filein = options .inputfile
94- if options .outputfile and not isinstance (options .outputfile , file ):
95+ if options .outputfile and not os . path . isfile (options .outputfile ):
9596 fileout = options .outputfile
9697 elif fileout != filedefault :
9798 fileout = '%s.py' % (path .splitext (filein )[0 ])
@@ -110,15 +111,15 @@ def runTransform(options):
110111 source = open (filein ).read ()
111112 else :
112113 source = sys .stdin .read ()
113- except (IOError , ), exc :
114+ except (IOError , ) as exc :
114115 code , msg = exc .args [0 :2 ]
115- print 'IOError: %s.' % (msg , )
116+ print ( 'IOError: %s.' % (msg , ) )
116117 return code
117118
118119 timed ['comp' ]
119120 try :
120121 tree = buildAST (source )
121- except (Exception , ), exc :
122+ except (Exception , ) as exc :
122123 exception ('exception while parsing' )
123124 return 1
124125 timed ['comp_finish' ]
@@ -164,7 +165,7 @@ def runTransform(options):
164165 if not options .skipcompile :
165166 try :
166167 compile (source , '<string>' , 'exec' )
167- except (SyntaxError , ), ex :
168+ except (SyntaxError , ) as ex :
168169 warning ('Generated source has invalid syntax. %s' , ex )
169170 else :
170171 info ('Generated source has valid syntax.' )
@@ -256,4 +257,4 @@ def configScript(argv):
256257
257258
258259if __name__ == '__main__' :
259- sys .exit (runMain (configScript (sys .argv [1 :])))
260+ sys .exit (runMain (configScript (sys .argv [1 :])))
0 commit comments