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


Python ast.PythonCode方法代码示例

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


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

示例1: undeclared_identifiers

# 需要导入模块: from mako import ast [as 别名]
# 或者: from mako.ast import PythonCode [as 别名]
def undeclared_identifiers(self):
        res = []
        for c in self.function_decl.defaults:
            res += list(
                ast.PythonCode(
                    c, **self.exception_kwargs
                ).undeclared_identifiers
            )
        return (
            set(res)
            .union(
                self.filter_args.undeclared_identifiers.difference(
                    filters.DEFAULT_ESCAPES.keys()
                )
            )
            .union(self.expression_undeclared_identifiers)
            .difference(self.function_decl.allargnames)
        ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:20,代码来源:parsetree.py

示例2: __init__

# 需要导入模块: from mako import ast [as 别名]
# 或者: from mako.ast import PythonCode [as 别名]
def __init__(self, namespace, defname, attributes, **kwargs):
        super(CallNamespaceTag, self).__init__(
            namespace + ":" + defname,
            attributes,
            tuple(attributes.keys()) + ("args",),
            (),
            (),
            **kwargs
        )

        self.expression = "%s.%s(%s)" % (
            namespace,
            defname,
            ",".join(
                [
                    "%s=%s" % (k, v)
                    for k, v in self.parsed_attributes.items()
                    if k != "args"
                ]
            ),
        )
        self.code = ast.PythonCode(self.expression, **self.exception_kwargs)
        self.body_decl = ast.FunctionArgs(
            attributes.get("args", ""), **self.exception_kwargs
        ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:27,代码来源:parsetree.py

示例3: __init__

# 需要导入模块: from mako import ast [as 别名]
# 或者: from mako.ast import PythonCode [as 别名]
def __init__(self, namespace, defname, attributes, **kwargs):
        super(CallNamespaceTag, self).__init__(
            namespace + ":" + defname,
            attributes,
            tuple(attributes.keys()) + ('args', ),
            (),
            (),
            **kwargs)

        self.expression = "%s.%s(%s)" % (
            namespace,
            defname,
            ",".join(["%s=%s" % (k, v) for k, v in
                      self.parsed_attributes.items()
                      if k != 'args'])
        )
        self.code = ast.PythonCode(self.expression, **self.exception_kwargs)
        self.body_decl = ast.FunctionArgs(
            attributes.get('args', ''),
            **self.exception_kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:parsetree.py

示例4: test_locate_identifiers_2

# 需要导入模块: from mako import ast [as 别名]
# 或者: from mako.ast import PythonCode [as 别名]
def test_locate_identifiers_2(self):
        code = """
import foobar
from lala import hoho, yaya
import bleep as foo
result = []
data = get_data()
for x in data:
    result.append(x+7)
"""
        parsed = ast.PythonCode(code, **exception_kwargs)
        eq_(parsed.undeclared_identifiers, set(["get_data"]))
        eq_(
            parsed.declared_identifiers,
            set(["result", "data", "x", "hoho", "foobar", "foo", "yaya"]),
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:18,代码来源:test_ast.py

示例5: test_locate_identifiers_2

# 需要导入模块: from mako import ast [as 别名]
# 或者: from mako.ast import PythonCode [as 别名]
def test_locate_identifiers_2(self):
        code = """
import foobar
from lala import hoho, yaya
import bleep as foo
result = []
data = get_data()
for x in data:
    result.append(x+7)
"""
        parsed = ast.PythonCode(code, **exception_kwargs)
        eq_(parsed.undeclared_identifiers, set(['get_data']))
        eq_(
            parsed.declared_identifiers,
            set(['result', 'data', 'x', 'hoho', 'foobar', 'foo', 'yaya'])
        ) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:18,代码来源:test_ast.py

示例6: _parse_attributes

# 需要导入模块: from mako import ast [as 别名]
# 或者: from mako.ast import PythonCode [as 别名]
def _parse_attributes(self, expressions, nonexpressions):
        undeclared_identifiers = set()
        self.parsed_attributes = {}
        for key in self.attributes:
            if key in expressions:
                expr = []
                for x in re.compile(r"(\${.+?})", re.S).split(
                    self.attributes[key]
                ):
                    m = re.compile(r"^\${(.+?)}$", re.S).match(x)
                    if m:
                        code = ast.PythonCode(
                            m.group(1).rstrip(), **self.exception_kwargs
                        )
                        # we aren't discarding "declared_identifiers" here,
                        # which we do so that list comprehension-declared
                        # variables aren't counted.   As yet can't find a
                        # condition that requires it here.
                        undeclared_identifiers = undeclared_identifiers.union(
                            code.undeclared_identifiers
                        )
                        expr.append("(%s)" % m.group(1))
                    else:
                        if x:
                            expr.append(repr(x))
                self.parsed_attributes[key] = " + ".join(expr) or repr("")
            elif key in nonexpressions:
                if re.search(r"\${.+?}", self.attributes[key]):
                    raise exceptions.CompileException(
                        "Attibute '%s' in tag '%s' does not allow embedded "
                        "expressions" % (key, self.keyword),
                        **self.exception_kwargs
                    )
                self.parsed_attributes[key] = repr(self.attributes[key])
            else:
                raise exceptions.CompileException(
                    "Invalid attribute for tag '%s': '%s'"
                    % (self.keyword, key),
                    **self.exception_kwargs
                )
        self.expression_undeclared_identifiers = undeclared_identifiers 
开发者ID:remg427,项目名称:misp42splunk,代码行数:43,代码来源:parsetree.py

示例7: _parse_attributes

# 需要导入模块: from mako import ast [as 别名]
# 或者: from mako.ast import PythonCode [as 别名]
def _parse_attributes(self, expressions, nonexpressions):
        undeclared_identifiers = set()
        self.parsed_attributes = {}
        for key in self.attributes:
            if key in expressions:
                expr = []
                for x in re.compile(r'(\${.+?})',
                                    re.S).split(self.attributes[key]):
                    m = re.compile(r'^\${(.+?)}$', re.S).match(x)
                    if m:
                        code = ast.PythonCode(m.group(1).rstrip(),
                                              **self.exception_kwargs)
                        # we aren't discarding "declared_identifiers" here,
                        # which we do so that list comprehension-declared
                        # variables aren't counted.   As yet can't find a
                        # condition that requires it here.
                        undeclared_identifiers = \
                            undeclared_identifiers.union(
                                code.undeclared_identifiers)
                        expr.append('(%s)' % m.group(1))
                    else:
                        if x:
                            expr.append(repr(x))
                self.parsed_attributes[key] = " + ".join(expr) or repr('')
            elif key in nonexpressions:
                if re.search(r'\${.+?}', self.attributes[key]):
                    raise exceptions.CompileException(
                        "Attibute '%s' in tag '%s' does not allow embedded "
                        "expressions" % (key, self.keyword),
                        **self.exception_kwargs)
                self.parsed_attributes[key] = repr(self.attributes[key])
            else:
                raise exceptions.CompileException(
                    "Invalid attribute for tag '%s': '%s'" %
                    (self.keyword, key),
                    **self.exception_kwargs)
        self.expression_undeclared_identifiers = undeclared_identifiers 
开发者ID:jpush,项目名称:jbox,代码行数:39,代码来源:parsetree.py

示例8: undeclared_identifiers

# 需要导入模块: from mako import ast [as 别名]
# 或者: from mako.ast import PythonCode [as 别名]
def undeclared_identifiers(self):
        res = []
        for c in self.function_decl.defaults:
            res += list(ast.PythonCode(c, **self.exception_kwargs).
                        undeclared_identifiers)
        return set(res).union(
            self.filter_args.
            undeclared_identifiers.
            difference(filters.DEFAULT_ESCAPES.keys())
        ).union(
            self.expression_undeclared_identifiers
        ).difference(
            self.function_decl.allargnames
        ) 
开发者ID:jpush,项目名称:jbox,代码行数:16,代码来源:parsetree.py


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