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


Python compiler.parse方法代码示例

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


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

示例1: check

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def check(s, frame=None):
    if frame is None:
        frame = sys._getframe(1)
        frame = py.code.Frame(frame)
    expr = parse(s, 'eval')
    assert isinstance(expr, ast.Expression)
    node = Interpretable(expr.node)
    try:
        node.eval(frame)
    except passthroughex:
        raise
    except Failure:
        e = sys.exc_info()[1]
        report_failure(e)
    else:
        if not frame.is_true(node.result):
            sys.stderr.write("assertion failed: %s\n" % node.nice_explanation())


###########################################################
# API / Entry points
# ######################################################### 
开发者ID:pytest-dev,项目名称:py,代码行数:24,代码来源:_assertionold.py

示例2: interpret

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def interpret(source, frame, should_fail=False):
    module = Interpretable(parse(source, 'exec').node)
    #print "got module", module
    if isinstance(frame, types.FrameType):
        frame = py.code.Frame(frame)
    try:
        module.run(frame)
    except Failure:
        e = sys.exc_info()[1]
        return getfailure(e)
    except passthroughex:
        raise
    except:
        import traceback
        traceback.print_exc()
    if should_fail:
        return ("(assertion failed, but when it was re-run for "
                "printing intermediate values, it did not fail.  Suggestions: "
                "compute assert expression before the assert or use --nomagic)")
    else:
        return None 
开发者ID:pytest-dev,项目名称:py,代码行数:23,代码来源:_assertionold.py

示例3: get_class_traits

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def get_class_traits(klass):
    """ Yield all of the documentation for trait definitions on a class object.
    """
    # FIXME: gracefully handle errors here or in the caller?
    source = inspect.getsource(klass)
    cb = CommentBlocker()
    cb.process_file(StringIO(source))
    mod_ast = compiler.parse(source)
    class_ast = mod_ast.node.nodes[0]
    for node in class_ast.code.nodes:
        # FIXME: handle other kinds of assignments?
        if isinstance(node, compiler.ast.Assign):
            name = node.nodes[0].name
            rhs = unparse(node.expr).strip()
            doc = strip_comment_marker(cb.search_for_comment(node.lineno, default=''))
            yield name, rhs, doc 
开发者ID:jakevdp,项目名称:supersmoother,代码行数:18,代码来源:comment_eater.py

示例4: interpret

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def interpret(source, frame, should_fail=False):
    module = Interpretable(parse(source, 'exec').node)
    #print "got module", module
    if isinstance(frame, py.std.types.FrameType):
        frame = py.code.Frame(frame)
    try:
        module.run(frame)
    except Failure:
        e = sys.exc_info()[1]
        return getfailure(e)
    except passthroughex:
        raise
    except:
        import traceback
        traceback.print_exc()
    if should_fail:
        return ("(assertion failed, but when it was re-run for "
                "printing intermediate values, it did not fail.  Suggestions: "
                "compute assert expression before the assert or use --nomagic)")
    else:
        return None 
开发者ID:acaceres2176,项目名称:scylla,代码行数:23,代码来源:_assertionold.py

示例5: CheckedEval

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def CheckedEval(file_contents):
  """Return the eval of a gyp file.

  The gyp file is restricted to dictionaries and lists only, and
  repeated keys are not allowed.

  Note that this is slower than eval() is.
  """

  ast = compiler.parse(file_contents)
  assert isinstance(ast, Module)
  c1 = ast.getChildren()
  assert c1[0] is None
  assert isinstance(c1[1], Stmt)
  c2 = c1[1].getChildren()
  assert isinstance(c2[0], Discard)
  c3 = c2[0].getChildren()
  assert len(c3) == 1
  return CheckNode(c3[0], []) 
开发者ID:zhaoolee,项目名称:StarsAndClown,代码行数:21,代码来源:input.py

示例6: run

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def run(s, frame=None):
    if frame is None:
        frame = sys._getframe(1)
        frame = py.code.Frame(frame)
    module = Interpretable(parse(s, 'exec').node)
    try:
        module.run(frame)
    except Failure:
        e = sys.exc_info()[1]
        report_failure(e) 
开发者ID:pytest-dev,项目名称:py,代码行数:12,代码来源:_assertionold.py

示例7: getObj

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def getObj(s):
    global compiler
    if compiler is None:
        import compiler
    s = "a=" + s
    p = compiler.parse(s)
    return p.getChildren()[1].getChildren()[0].getChildren()[1] 
开发者ID:OWASP,项目名称:NINJA-PingU,代码行数:9,代码来源:configobj.py

示例8: _get_tree

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def _get_tree(self):
        tree = parse(self.source, self.mode)
        misc.set_filename(self.filename, tree)
        syntax.check(tree)
        return tree 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:pycodegen.py

示例9: parse

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def parse(self, text, name="<template>"):
        self.text = text
        self.name = name
        
        defwith, text = self.read_defwith(text)
        suite = self.read_suite(text)
        return DefwithNode(defwith, suite) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:9,代码来源:template.py

示例10: generate_code

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def generate_code(text, filename, parser=None):
        # parse the text
        parser = parser or Parser()
        rootnode = parser.parse(text, filename)
                
        # generate python code from the parse tree
        code = rootnode.emit(indent="").strip()
        return safestr(code) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:10,代码来源:template.py

示例11: string_build

# 需要导入模块: import compiler [as 别名]
# 或者: from compiler import parse [as 别名]
def string_build(self, data, modname='', path=None):
        """build astng from a source code stream (i.e. from an ast)"""
        return self.ast_build(parse(data + '\n'), modname, path) 
开发者ID:jlachowski,项目名称:clonedigger,代码行数:5,代码来源:builder.py


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