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


Python ast.Tuple方法代码示例

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


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

示例1: pyjs_builtin_remap

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Tuple [as 别名]
def pyjs_builtin_remap(name):
    # XXX HACK!
    if name == 'list':
        name = 'List'
    if name == 'object':
        name = '__Object'
    if name == 'dict':
        name = 'Dict'
    if name == 'tuple':
        name = 'Tuple'
    return name


# XXX: this is a hack: these should be dealt with another way
# however, console is currently the only global name which is causing
# problems. 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:18,代码来源:pyjs.py

示例2: _AssTuple

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Tuple [as 别名]
def _AssTuple(self, t):
        """ Tuple on left hand side of an expression.
        """

        # _write each elements, separated by a comma.
        for element in t.nodes[:-1]:
            self._dispatch(element)
            self._write(", ")

        # Handle the last one without writing comma
        last_element = t.nodes[-1]
        self._dispatch(last_element) 
开发者ID:jakevdp,项目名称:supersmoother,代码行数:14,代码来源:compiler_unparse.py

示例3: _Return

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Tuple [as 别名]
def _Return(self, t):
        self._fill("return ")
        if t.value:
            if isinstance(t.value, Tuple):
                text = ', '.join([ name.name for name in t.value.asList() ])
                self._write(text)
            else:
                self._dispatch(t.value)
            if not self._do_indent:
                self._write('; ') 
开发者ID:jakevdp,项目名称:supersmoother,代码行数:12,代码来源:compiler_unparse.py

示例4: _varargs_handler

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Tuple [as 别名]
def _varargs_handler(self, node, varargname, arg_names, current_klass):
        self.printo("    var", varargname, '= new pyjslib.Tuple();')
        self.printo("    for(var __va_arg="+str(len(arg_names))+"; __va_arg < arguments.length; __va_arg++) {")
        self.printo("        var __arg = arguments[__va_arg];")
        self.printo("        "+varargname+".append(__arg);")
        self.printo("    }") 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:8,代码来源:pyjs.py

示例5: _tryExcept

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Tuple [as 别名]
def _tryExcept(self, node, current_klass):
        if len(node.handlers) != 1:
            raise TranslationError("except statements in this form are" +
                                   " not supported", node)

        expr = node.handlers[0][0]
        as_ = node.handlers[0][1]
        if as_:
            errName = as_.name
        else:
            errName = 'err'

        # XXX TODO: check that this should instead be added as a _separate_
        # local scope, temporary to the function.  oh dearie me.
        self.add_local_arg(errName)

        self.printo("    try {")
        for stmt in node.body.nodes:
            self._stmt(stmt, current_klass)
        self.printo("    } catch(%s) {" % errName)
        if expr:
            k = []
            if isinstance(expr, ast.Tuple):
                for x in expr.nodes:
                    k.append("(%(err)s.__name__ == %(expr)s.__name__)" % dict(err=errName, expr=self.expr(x, current_klass)))
            else:
                k = [" (%(err)s.__name__ == %(expr)s.__name__) " % dict(err=errName, expr=self.expr(expr, current_klass))]
            self.printo("   if(%s) {" % '||\n\t\t'.join(k))
        for stmt in node.handlers[0][2]:
            self._stmt(stmt, current_klass)
        if expr:
            # self.printo("} else { throw(%s); } " % errName)
            self.printo("}")
        if node.else_ is not None:
            self.printo("    } finally {")
            for stmt in node.else_:
                self._stmt(stmt, current_klass)
        self.printo("    }")

    # XXX: change use_getattr to True to enable "strict" compilation
    # but incurring a 100% performance penalty. oops. 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:43,代码来源:pyjs.py

示例6: _tuple

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Tuple [as 别名]
def _tuple(self, node, current_klass):
        return "new pyjslib.Tuple([" + ", ".join([self.expr(x, current_klass) for x in node.nodes]) + "])" 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:4,代码来源:pyjs.py

示例7: safe_eval

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Tuple [as 别名]
def safe_eval(node_or_string, env):
    """
    Safely evaluate an expression node or a string containing a Python
    expression.  The string or node provided may only consist of the following
    Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
    and None.
    """
    _safe_names = {'None': None, 'True': True, 'False': False}
    _safe_names.update(env)
    if isinstance(node_or_string, basestring):
        node_or_string = ast_parse(node_or_string, mode='eval')
    if isinstance(node_or_string, ast.Expression):
        node_or_string = node_or_string.body
    def _convert(node):
        if isinstance(node, ast.Str):
            return node.s
        elif isinstance(node, ast.Num):
            return node.n
        elif isinstance(node, ast.Tuple):
            return tuple(map(_convert, node.elts))
        elif isinstance(node, ast.List):
            return list(map(_convert, node.elts))
        elif isinstance(node, ast.Dict):
            return dict((_convert(k), _convert(v)) for k, v
                        in zip(node.keys, node.values))
        elif isinstance(node, ast.Name):
            if node.id in _safe_names:
                return _safe_names[node.id]
        elif isinstance(node, ast.BinOp) and \
             isinstance(node.op, (Add, Sub)) and \
             isinstance(node.right, Num) and \
             isinstance(node.right.n, complex) and \
             isinstance(node.left, Num) and \
             isinstance(node.left.n, (int, long, float)):
            left = node.left.n
            right = node.right.n
            if isinstance(node.op, Add):
                return left + right
            else:
                return left - right
        raise ValueError('malformed string')
    return _convert(node_or_string) 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:44,代码来源:markmin2html.py

示例8: expr

# 需要导入模块: from compiler import ast [as 别名]
# 或者: from compiler.ast import Tuple [as 别名]
def expr(self, node, current_klass):
        if isinstance(node, ast.Const):
            return self._const(node)
        # @@@ not sure if the parentheses should be here or in individual operator functions - JKT
        elif isinstance(node, ast.Mul):
            return " ( " + self._mul(node, current_klass) + " ) "
        elif isinstance(node, ast.Add):
            return " ( " + self._add(node, current_klass) + " ) "
        elif isinstance(node, ast.Sub):
            return " ( " + self._sub(node, current_klass) + " ) "
        elif isinstance(node, ast.Div):
            return " ( " + self._div(node, current_klass) + " ) "
        elif isinstance(node, ast.Mod):
            return self._mod(node, current_klass)
        elif isinstance(node, ast.UnaryAdd):
            return self._unaryadd(node, current_klass)
        elif isinstance(node, ast.UnarySub):
            return self._unarysub(node, current_klass)
        elif isinstance(node, ast.Not):
            return self._not(node, current_klass)
        elif isinstance(node, ast.Or):
            return self._or(node, current_klass)
        elif isinstance(node, ast.And):
            return self._and(node, current_klass)
        elif isinstance(node, ast.Invert):
            return self._invert(node, current_klass)
        elif isinstance(node, ast.Bitand):
            return "("+self._bitand(node, current_klass)+")"
        elif isinstance(node, ast.LeftShift):
            return self._bitshiftleft(node, current_klass)
        elif isinstance(node, ast.RightShift):
            return self._bitshiftright(node, current_klass)
        elif isinstance(node, ast.Bitxor):
            return "("+self._bitxor(node, current_klass)+")"
        elif isinstance(node, ast.Bitor):
            return "("+self._bitor(node, current_klass)+")"
        elif isinstance(node, ast.Compare):
            return self._compare(node, current_klass)
        elif isinstance(node, ast.CallFunc):
            return self._callfunc(node, current_klass)
        elif isinstance(node, ast.Name):
            return self._name(node, current_klass)
        elif isinstance(node, ast.Subscript):
            return self._subscript(node, current_klass)
        elif isinstance(node, ast.Getattr):
            return self._getattr(node, current_klass)
        elif isinstance(node, ast.List):
            return self._list(node, current_klass)
        elif isinstance(node, ast.Dict):
            return self._dict(node, current_klass)
        elif isinstance(node, ast.Tuple):
            return self._tuple(node, current_klass)
        elif isinstance(node, ast.Slice):
            return self._slice(node, current_klass)
        elif isinstance(node, ast.Lambda):
            return self._lambda(node, current_klass)
        else:
            raise TranslationError("unsupported type (in expr)", node) 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:60,代码来源:pyjs.py


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