當前位置: 首頁>>代碼示例>>Python>>正文


Python pyparser.FindIdentifiers方法代碼示例

本文整理匯總了Python中mako.pyparser.FindIdentifiers方法的典型用法代碼示例。如果您正苦於以下問題:Python pyparser.FindIdentifiers方法的具體用法?Python pyparser.FindIdentifiers怎麽用?Python pyparser.FindIdentifiers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mako.pyparser的用法示例。


在下文中一共展示了pyparser.FindIdentifiers方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from mako import pyparser [as 別名]
# 或者: from mako.pyparser import FindIdentifiers [as 別名]
def __init__(self, code, **exception_kwargs):
        self.code = code

        # represents all identifiers which are assigned to at some point in
        # the code
        self.declared_identifiers = set()

        # represents all identifiers which are referenced before their
        # assignment, if any
        self.undeclared_identifiers = set()

        # note that an identifier can be in both the undeclared and declared
        # lists.

        # using AST to parse instead of using code.co_varnames,
        # code.co_names has several advantages:
        # - we can locate an identifier as "undeclared" even if
        # its declared later in the same block of code
        # - AST is less likely to break with version changes
        # (for example, the behavior of co_names changed a little bit
        # in python version 2.5)
        if isinstance(code, compat.string_types):
            expr = pyparser.parse(code.lstrip(), "exec", **exception_kwargs)
        else:
            expr = code

        f = pyparser.FindIdentifiers(self, **exception_kwargs)
        f.visit(expr) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:30,代碼來源:ast.py


注:本文中的mako.pyparser.FindIdentifiers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。