本文整理汇总了Python中Object.Object.setGlobalType方法的典型用法代码示例。如果您正苦于以下问题:Python Object.setGlobalType方法的具体用法?Python Object.setGlobalType怎么用?Python Object.setGlobalType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object.Object
的用法示例。
在下文中一共展示了Object.setGlobalType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mind
# 需要导入模块: from Object import Object [as 别名]
# 或者: from Object.Object import setGlobalType [as 别名]
class Mind() :
def __init__(self):
self.sources = ''
self.sourceList = []
self.walker = Walker()
self.classes = {}
self.glob = Object('<global>')
self.glob.setGlobalType()
classFinder = ClassFinder(self.glob, self.classes)
scopeTracer = ScopeTracer()
# self.walker.addWatcher(scopeTracer)
self.walker.addWatcher(classFinder)
def setSources(self, sources):
self.sources = sources + '/'
self.sourceList = []
for file in os.listdir(sources):
name = file.split('.')
if name[len(name)-1] == 'js':
self.sourceList.append(SourceFile(file))
def getSourcesList(self):
return jsonEncoder.encode(self.sourceList)
def updateParseCache(self):
for file in self.sourceList:
self.updateFileAST(file)
def updateFileAST(self, file):
filename = self.sources + file.path
parsed = filename + '.ast'
AST = None
if not os.path.exists(parsed) or os.path.getmtime(parsed) < os.path.getmtime(filename):
from Rishi.parser.JSParser import Parser
parser = Parser()
parser.src = open(filename).read()
parser.buildAST()
import pickle
pickle.dump(parser.ASTRoot, open(parsed,'wb'), pickle.HIGHEST_PROTOCOL)
def loadAST(self):
for file in self.sourceList:
self.parseSourceFile(file)
def parseSourceFile(self, file):
ast = self.updateFileAST(file)
if ast == None:
import pickle
filename = self.sources + file.path
parsed = filename + '.ast'
ast = pickle.load(open(parsed,'rb'))
file.setAST(ast)
def findHidden(self):
for file in self.sourceList:
if file.parsed and file.ast:
print (file.path)
self.walker.setAst(file.ast)
self.walker.walk()
self.saveObjects()
def saveObjects(self):
file = open(self.outputDir + '/ObjectTree.json','w')
file.write(jsonSerializer.serialize(self.glob))
file = open(self.outputDir + '/classes.json','w')
file.write(jsonSerializer.serialize(list(self.classes.keys())))
def setOutputDir(self, outputDir):
self.outputDir = outputDir