當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。