def testFiles(listOfFiles, PyduckerWarningOff): for i in listOfFiles: aFile = i.name with open(aFile, 'r') as f: fileCont = f.read() print("File name: ",aFile) try: tree = ast.parse(fileCont, aFile) #except ast.parser.ParseError: # print('hit') except BaseException: type, value, tb = sys.exc_info() print("Unable to parser file due to" ,type.__name__) print( type.__name__, ":" , value) tree = None if PyduckerWarningOff: try: nameSpace = handMakeNameSpace() scope = handMakeScope() firstWalker = InitialWalker(tree, nameSpace, scope) firstWalker.walk() except Exceptions.PyDuckerError as ex: print("\n", ex.__class__.__name__, end = "") print(ex) except Exceptions.PyDuckerWarning as ex: pass finally: print() else: try: nameSpace = handMakeNameSpace() scope = handMakeScope() firstWalker = InitialWalker(tree, nameSpace, scope) firstWalker.walk() except Exceptions.PyDuckerException as ex: print("\n", ex.__class__.__name__, end = "") print(ex) finally: print()
def testFiles(listOfFiles, PyduckerWarningOff): for i in listOfFiles: aFile = i.name with open(aFile, 'r') as f: fileCont = f.read() print("File name: ", aFile) try: tree = ast.parse(fileCont, aFile) #except ast.parser.ParseError: # print('hit') except BaseException: type, value, tb = sys.exc_info() print("Unable to parser file due to", type.__name__) print(type.__name__, ":", value) tree = None if PyduckerWarningOff: try: nameSpace = handMakeNameSpace() scope = handMakeScope() firstWalker = InitialWalker(tree, nameSpace, scope) firstWalker.walk() except Exceptions.PyDuckerError as ex: print("\n", ex.__class__.__name__, end="") print(ex) except Exceptions.PyDuckerWarning as ex: pass finally: print() else: try: nameSpace = handMakeNameSpace() scope = handMakeScope() firstWalker = InitialWalker(tree, nameSpace, scope) firstWalker.walk() except Exceptions.PyDuckerException as ex: print("\n", ex.__class__.__name__, end="") print(ex) finally: print()
def testOne(aFile): """ @aFile:str """ #open a file and get it read into a variable so it is just one string print("Reading file ", aFile) with open(aFile, 'r') as f: fileCont = f.read() #parse the string into an ast using the builtin function tree = ast.parse(fileCont, aFile) print ((ast.dump(tree))) nameSpace = handMakeNameSpace() scope = handMakeScope() firstWalker = InitialWalker(tree, nameSpace, scope) firstWalker.walk() print("")
def _testAll(listOfFiles): for i in listOfFiles: aFile = i #print("Reading file ", aFile) with open(aFile, 'r') as f: fileCont = f.read() print("File name: ",aFile) tree = ast.parse(fileCont, aFile) print("Tree Dump: ",ast.dump(tree)) try: nameSpace = handMakeNameSpace() scope = handMakeScope() firstWalker = InitialWalker(tree, nameSpace, scope) firstWalker.walk() except Exceptions.PyDuckerException as ex: # print(ex, file=sys.stderr) #printing to sys.stderr will need to be locked so output flows correctly, otherwise the messages come out interwoven. print("\n", ex.__class__.__name__, end= "" ) print(ex) finally: print()