当前位置: 首页>>代码示例>>Python>>正文


Python symtable.symtable函数代码示例

本文整理汇总了Python中symtable.symtable函数的典型用法代码示例。如果您正苦于以下问题:Python symtable函数的具体用法?Python symtable怎么用?Python symtable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了symtable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: checkfilename

 def checkfilename(brokencode):
     try:
         symtable.symtable(brokencode, "spam", "exec")
     except SyntaxError as e:
         self.assertEqual(e.filename, "spam")
     else:
         self.fail("no SyntaxError for %r" % (brokencode,))
开发者ID:BillyboyD,项目名称:main,代码行数:7,代码来源:test_symtable.py

示例2: test_annotated

 def test_annotated(self):
     st1 = symtable.symtable('def f():\n    x: int\n', 'test', 'exec')
     st2 = st1.get_children()[0]
     self.assertTrue(st2.lookup('x').is_local())
     self.assertTrue(st2.lookup('x').is_annotated())
     self.assertFalse(st2.lookup('x').is_global())
     st3 = symtable.symtable('def f():\n    x = 1\n', 'test', 'exec')
     st4 = st3.get_children()[0]
     self.assertTrue(st4.lookup('x').is_local())
     self.assertFalse(st4.lookup('x').is_annotated())
开发者ID:1st1,项目名称:cpython,代码行数:10,代码来源:test_symtable.py

示例3: __tests

def __tests():
    import symtable

    class ClassFinder(ast.NodeVisitor):
        def __init__(self, name):
            ast.NodeVisitor.__init__(self)
            self.name = name
            self.classes = []

        def visit_ClassDef(self, node):
            if node.name == self.name:
                self.classes.append(node)

    with open('tests/game2.py') as source_file:
        code = source_file.read()
        ast_node = ast.parse(code)
        symbol_table = symtable.symtable(code, 'game2.py', 'exec')
        class_finder = ClassFinder('Game')
        class_finder.visit(ast_node)
        subclass = class_finder.classes[0]
        subclass_symbol_table = symbol_table.lookup('Game').get_namespace()
        superclasses, subclass = SuperClassExtractor.extract_into_ideal_cohesion(subclass, subclass_symbol_table)
        for superclass_node in superclasses:
            print to_source(superclass_node)
            # print
            # print ast.dump(superclass_node)
            print
            print '#' * 200
            print
        print to_source(subclass)
开发者ID:wolmir,项目名称:cristina,代码行数:30,代码来源:codebase_recycling.py

示例4: __init__

 def __init__(self, code, ns=None):
     global __default_namespace__
     if ns is None:
         ns = __default_namespace__
     var = [v for v in symtable.symtable(code, '<string>', 'exec').get_identifiers() if v in ns]
     super(PythonCode, self).__init__(var=var, namespace=ns)
     self.code = compile(code, '<string>', 'exec')
开发者ID:Abramovuch,项目名称:sagecell,代码行数:7,代码来源:interact_namespace.py

示例5: parse_module

def parse_module(module_name):
    filename = module_name + ".py"
    with open(os.path.join(SOLUTIONS_DIR, filename), 'r') as f:
        source = f.read()

    srclines = source.splitlines()
    module = ast.parse(source, filename)
    table = symtable.symtable(source, filename, "exec")
    stmts = list(get_stmts(module))
    last_fun = stmts[0][0]
    lines = {name:"\n".join(srclines[s:e]).strip() for (name,(s,e)) in stmts}
    imports = dict(get_imports(module))

    def parse_dependencies(name):
        import builtins
        for tab in get_child_tables(table.lookup(name).get_namespace()):
            for g in tab.get_globals():
                if g in dir(builtins):
                    continue

                if table.lookup(g).is_imported():
                    imported = imports[g]
                    if imported[0] != "leetcode":
                        yield imported
                else:
                    yield (module_name, g)

    return last_fun, lines, {name:tuple(parse_dependencies(name)) for name in lines}
开发者ID:bhuztez,项目名称:leetcode-solution,代码行数:28,代码来源:c.py

示例6: _inspect

 def _inspect(self,string):
   symtab = symtable.symtable(string,'rule',self.mode)
   symbols = symtab.get_symbols()
   defs = [sym.get_name() for sym in symbols if sym.is_assigned()]
   refs = [sym.get_name() for sym in symbols if sym.is_referenced()]
   self.all_symbols = frozenset(symtab.get_identifiers())
   self.sym_assigned = defset = frozenset(defs)
   self.sym_internal = frozenset(defset.intersection(refs))
开发者ID:Huskyeder,项目名称:augustus,代码行数:8,代码来源:rules.py

示例7: __find_class_symbol_tables

 def __find_class_symbol_tables(self):
     class_names = self.__get_class_names()
     source_code = self.get_source_code()
     module_symbol_table = symtable.symtable(source_code, self.file_path, 'exec')
     symbol_tables = []
     for name in class_names:
         class_symbol_table = module_symbol_table.lookup(name).get_namespace()
         symbol_tables.append(class_symbol_table)
     return symbol_tables
开发者ID:wolmir,项目名称:cristina,代码行数:9,代码来源:codebase_recycling.py

示例8: get_symtable

def get_symtable(path):
	import symtable
	try:
		st = symtables[path]
	except KeyError:
		with open(path, 'r') as f:
			st = symtable.symtable(f.read(), path, 'exec')
		symtables[path] = st
	return st
开发者ID:raylu,项目名称:pigwig,代码行数:9,代码来源:conf.py

示例9: __init__

 def __init__(self, source_no_encoding, pubapi):
     # Our public API (__all__)
     self.pubapi = pubapi
     # Names of imported modules
     self.modnames = []
     self.symtab = symtable.symtable(source_no_encoding, "-", "exec")
     cst = parser.suite(source_no_encoding)
     elements = parser.ast2tuple(cst, line_info=1)
     self.names = {}
     self.walk(elements, [self.symtab])
开发者ID:Sevenops,项目名称:Simple-Scripts,代码行数:10,代码来源:o.py

示例10: __init__

 def __init__(self, source, path='<string>'):
     self.source = source
     self.path = path
     self.ast = ast.parse(source, path)
     self.symtable = symtable.symtable(source, path, 'exec')
     self.tokens = tokenize_string(source)
     cw = ChainWalker(self.ast, self.symtable)
     self.nodes = cw.nodes
     TokenAssociator(self.nodes, self.tokens)
     self.ast_map = {node.ast_node: node for node in self.nodes}
开发者ID:kentfrazier,项目名称:parsnip,代码行数:10,代码来源:__init__.py

示例11: format_table

def format_table(code_string):
    s_table = symtable(code_string, "string", "exec")
    table = []
    for child in s_table.get_children():
        row = {
            "name": child.get_name(),
            "scope": "global",
            "children": [subchild.get_name() for subchild in child.get_children()],
        }
        table.append(row)
    return s_table, table
开发者ID:DivyaShanmugam,项目名称:MoAL,代码行数:11,代码来源:symbol_table.py

示例12: getDefinitions

 def getDefinitions(self, doc, identifier):
     if doc.get_language().get_name() != "Python":
         return
     doc_location = doc.get_location()
     with open(doc_location.get_path()) as f:
         table = symtable.symtable(
             f.read(),
             doc_location.get_basename(),
             "exec",
         )
         for line in self.generateDefLines(table, identifier):
             yield doc_location, line, "", doc_location.get_path()
开发者ID:jmanoel7,项目名称:my_dot_files,代码行数:12,代码来源:PythonSymtableNavigator.py

示例13: load_file

    def load_file(filename):
        filename = os.path.abspath(filename)
        with open(filename) as fp:
            syminfo = symtable.symtable(fp.read() + '\n', filename, 'exec')

        if(os.path.splitext(filename)[1] == '.py'):
            try:
                py_compile.compile(filename, filename+'c', doraise=True)
            except py_compile.PyCompileError, msg:
                print str(msg)
                print 'Couldn\'t compile %s, stopping.' % filename
                os._exit(0)
            filename += 'c'
开发者ID:sataloger,项目名称:python-static-analysis,代码行数:13,代码来源:cfg_creator.py

示例14: test_annotated

    def test_annotated(self):
        st1 = symtable.symtable('def f():\n    x: int\n', 'test', 'exec')
        st2 = st1.get_children()[0]
        self.assertTrue(st2.lookup('x').is_local())
        self.assertTrue(st2.lookup('x').is_annotated())
        self.assertFalse(st2.lookup('x').is_global())
        st3 = symtable.symtable('def f():\n    x = 1\n', 'test', 'exec')
        st4 = st3.get_children()[0]
        self.assertTrue(st4.lookup('x').is_local())
        self.assertFalse(st4.lookup('x').is_annotated())

        # Test that annotations in the global scope are valid after the
        # variable is declared as nonlocal.
        st5 = symtable.symtable('global x\nx: int', 'test', 'exec')
        self.assertTrue(st5.lookup("x").is_global())

        # Test that annotations for nonlocals are valid after the
        # variable is declared as nonlocal.
        st6 = symtable.symtable('def g():\n'
                                '    x = 2\n'
                                '    def f():\n'
                                '        nonlocal x\n'
                                '    x: int',
                                'test', 'exec')
开发者ID:Eyepea,项目名称:cpython,代码行数:24,代码来源:test_symtable.py

示例15: test_filename_correct

 def test_filename_correct(self):
     ### Bug tickler: SyntaxError file name correct whether error raised
     ### while parsing or building symbol table.
     def checkfilename(brokencode):
         try:
             symtable.symtable(brokencode, "spam", "exec")
         except SyntaxError as e:
             self.assertEqual(e.filename, "spam")
         else:
             self.fail("no SyntaxError for %r" % (brokencode,))
     checkfilename("def f(x): foo)(")  # parse-time
     checkfilename("def f(x): global x")  # symtable-build-time
     symtable.symtable("pass", b"spam", "exec")
     with self.assertRaises(TypeError):
         symtable.symtable("pass", bytearray(b"spam"), "exec")
     symtable.symtable("pass", memoryview(b"spam"), "exec")
     with self.assertRaises(TypeError):
         symtable.symtable("pass", list(b"spam"), "exec")
开发者ID:CabbageHead-360,项目名称:cpython,代码行数:18,代码来源:test_symtable.py


注:本文中的symtable.symtable函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。