Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)

        def mk_escaper (ast_module):
    def myescape (obj):
        """myescape(obj) Translate the given AST into a Python AST
        that can be evaluated to construct the given AST."""
        if isinstance(obj, ast_module.AST):
            ast_type = type(obj)
            esc_args = [myescape(getattr(obj, ctor_arg))
                        for ctor_arg in ast_type.__init__.func_code.co_names]
            ret_val = myfront_ast.Call(myfront_ast.Name(ast_type.__name__,
                                       esc_args, [], None, None)
        elif isinstance(obj, dict):
            keyobjs = obj.keys()
            ret_val = myfront_ast.Dict(
                [myescape(keyobj) for keyobj in keyobjs],
                [myescape(obj[keyobj]) for keyobj in keyobjs])
        elif isinstance(obj, list):
            ret_val = myfront_ast.List([myescape(subobj) for subobj in obj],
        elif isinstance(obj, tuple):
            ret_val = myfront_ast.Tuple([myescape(subobj) for subobj in obj],
        elif isinstance(obj, int):
            ret_val = myfront_ast.Num(obj)
        elif isinstance(obj, float):
            ret_val = myfront_ast.Num(obj)
        elif isinstance(obj, str):
            ret_val = myfront_ast.Str(obj)
        elif obj is None:
            ret_val = myfront_ast.Name("None", myfront_ast.Load())
            raise NotImplementedError("Don't know how to escape '%r'!" % (obj))
        return ret_val
    return myescape

src/m/y/mython-HEAD/basil/lang/mython/mybuiltins.py   mython(Download)
# ______________________________________________________________________
myescape = _ASTUtils.mk_escaper(_ast)
# ______________________________________________________________________