def assign(conv, node, scope): rest = '' target = node.targets[0] if isinstance(target, ast.Tuple): left = 'var __pjs_tmp' rest = utils.deepleft(conv, target, [], scope) elif isinstance(target, ast.Subscript): left = conv.get_converter(target)(conv, target, scope, True) if left.endswith(' '): return left + conv.convert_node(node.value, scope) + ');\n' elif isinstance(target, ast.Name): left = utils.lhand_assign(target.id, scope) else: left = conv.convert_node(target, scope) for targ in node.targets[1:]: var = left if var.startswith('var '): var = var[len('var '):] if isinstance(targ, ast.Tuple): rest += utils.deepleft(conv, targ, [], scope, var) elif isinstance(targ, ast.Name): mr = utils.lhand_assign(targ.id, scope) rest += mr + ' = ' + var + ';\n' else: rest += '%s = %s;\n' % (conv.convert_node(targ, scope), var) js = conv.convert_node(node.value, scope) line = '%s = %s;\n' % (left, js) return line + rest
def _for(conv, node, scope): ible = conv.convert_node(node.iter, scope) temp_iter = conv.get_temp('iter') if isinstance(node.target, ast.Name): targ = utils.lhand_assign(node.target.id, scope) assign = '%s = %s.value;\n' % (targ, temp_iter) else: assign = utils.deepleft(conv, node.target, [], scope, '%s.value' % temp_iter).replace( '\n', '\n ') body = conv.convert_block(node.body, scope) conv.kill_temp('iter') return FOR_TPL % (temp_iter, ible, temp_iter, assign, body)