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


Python symtable.symtable方法代码示例

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


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

示例1: __init__

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
def __init__(self, code: str, key: bytes, ns_manager: BuiltInManager):
        self.symbol_table: symtable = symtable(code, '<string>', 'exec')
        self.code: str = code
        self.input_vars: List[SymbolWrapper] = CodeObject._find_input_variables(self.symbol_table, ns_manager
                                                                                )
        self.output_vars: FrozenSet[SymbolWrapper] = CodeObject._find_output_variables(self.symbol_table
                                                                                       )

        h = blake2b(digest_size=10, key=key)
        if len(self.output_vars) > 0:
            display_id_prefix = "+".join(map(str, self.output_vars))
            h.update(display_id_prefix.encode('utf-8'))
            self.display_id = f"{display_id_prefix}-{h.hexdigest()}"
        else:
            h.update(self.code.encode('utf-8'))
            self.display_id = f"{h.hexdigest()}" 
开发者ID:jupytercalpoly,项目名称:reactivepy,代码行数:18,代码来源:code_object.py

示例2: test_filename_correct

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
def test_filename_correct(self):
        ### Bug tickler: SyntaxError file name correct whether error raised
        ### while parsing or building symbol table.
        def checkfilename(brokencode, offset):
            try:
                symtable.symtable(brokencode, "spam", "exec")
            except SyntaxError as e:
                self.assertEqual(e.filename, "spam")
                self.assertEqual(e.lineno, 1)
                self.assertEqual(e.offset, offset)
            else:
                self.fail("no SyntaxError for %r" % (brokencode,))
        checkfilename("def f(x): foo)(", 14)  # parse-time
        checkfilename("def f(x): global x", 10)  # 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:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:22,代码来源:test_symtable.py

示例3: onelinerize

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
def onelinerize(original):
    # original :: string
    # :: string
    t = ast.parse(original)
    table = symtable.symtable(original, '<string>', 'exec')

    original = original.strip()

    # If there's only one line anyways, be lazy
    if len(original.splitlines()) == 1 and \
       len(t.body) == 1 and \
       type(t.body[0]) in (ast.Delete, ast.Assign, ast.AugAssign, ast.Print,
                           ast.Raise, ast.Assert, ast.Import, ast.ImportFrom,
                           ast.Exec, ast.Global, ast.Expr, ast.Pass):
        return original

    return get_init_code(t, table) 
开发者ID:csvoss,项目名称:onelinerizer,代码行数:19,代码来源:onelinerizer.py

示例4: get_inferred_type

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
def get_inferred_type(self, name):
        # type: (str) -> Any
        # Given a symbol name, check whether a type
        # has been inferred.
        # The stdlib symtable will already fall back to
        # global scope if necessary.
        symbol = self._local_table.lookup(name)
        if symbol.is_global():
            try:
                global_symbol = self._global_table.lookup(name)
            except KeyError:
                # It's not an error if a symbol.is_global()
                # but is not in our "_global_table", because
                # we're not considering the builtin scope.
                # In this case we just say that there is no
                # type we've inferred.
                return None
            return getattr(global_symbol, 'inferred_type', None)
        return getattr(symbol, 'inferred_type', None) 
开发者ID:aws,项目名称:chalice,代码行数:21,代码来源:analyzer.py

示例5: test_filename_correct

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
def test_filename_correct(self):
        ### Bug tickler: SyntaxError file name correct whether error raised
        ### while parsing or building symbol table.
        def checkfilename(brokencode, offset):
            try:
                symtable.symtable(brokencode, "spam", "exec")
            except SyntaxError as e:
                self.assertEqual(e.filename, "spam")
                self.assertEqual(e.lineno, 1)
                self.assertEqual(e.offset, offset)
            else:
                self.fail("no SyntaxError for %r" % (brokencode,))
        checkfilename("def f(x): foo)(", 14)  # parse-time
        checkfilename("def f(x): global x", 10)  # symtable-build-time
        symtable.symtable("pass", b"spam", "exec")
        with self.assertWarns(DeprecationWarning), \
             self.assertRaises(TypeError):
            symtable.symtable("pass", bytearray(b"spam"), "exec")
        with self.assertWarns(DeprecationWarning):
            symtable.symtable("pass", memoryview(b"spam"), "exec")
        with self.assertRaises(TypeError):
            symtable.symtable("pass", list(b"spam"), "exec") 
开发者ID:bkerler,项目名称:android_universal,代码行数:24,代码来源:test_symtable.py

示例6: test_filename_correct

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_symtable.py

示例7: test_eval

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
def test_eval(self):
        symbols = symtable.symtable("42", "?", "eval") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_symtable.py

示例8: test_single

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
def test_single(self):
        symbols = symtable.symtable("42", "?", "single") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_symtable.py

示例9: test_exec

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
def test_exec(self):
        symbols = symtable.symtable("def f(x): return x", "?", "exec") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_symtable.py

示例10: format_table

# 需要导入模块: import symtable [as 别名]
# 或者: from symtable import symtable [as 别名]
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:christabor,项目名称:MoAL,代码行数:14,代码来源:symbol_table.py


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