def visit_callfunc(self, c): if inference.infer_qname(c.func) == "prambanan.native.get_template": template_type = inference.ConstEvaluator().visit(c.args[0]) template_config = inference.ConstEvaluator().visit(c.args[1]) template = (template_type, template_config) if not template in self.templates: self.templates.append(template)
def is_js_noop(self, dec): inferred = list(inference.infer(dec)) if len(inferred) == 1: inferred_dec = inferred[0] if isinstance( inferred_dec, nodes.Function) and inferred_dec.decorators is not None: for dec_dec in inferred_dec.decorators.nodes: if inference.infer_qname( dec_dec) == "prambanan.JS_noop_marker": return True return False
def visit_callfunc(self, c): """ Translates a function/method call or class instantiation. every named arguments became keyword arguments """ cls = self.curr_scope.class_context() type = self.infer_call_type(c.func) name = None call_type = None method_written = False if inference.infer_qname(c.func) == "prambanan.JS": if len(c.args) != 1: raise ParseError("native js only accept one argument", c.lineno, c.col_offset) if not isinstance(c.args[0], nodes.Const) and not isinstance(c.args[0].value, str): raise ParseError("native js only accept string",c.lineno, c.col_offset) self.write(re.sub(r'(?:@{{[!]?)([^}}]*)(?:}})', r"\1",c.args[0].value)) return if isinstance(c.func, nodes.Name): call_type = "name" elif isinstance(c.func, nodes.Getattr): call_type = "getattr" if cls is not None and isinstance(c.func.expr, nodes.CallFunc) and isinstance(c.func.expr.func, nodes.Name) : if c.func.expr.func.name == "super": # A super call if (not len(c.func.expr.args) == 2): self.raise_error("Only python 2 simple super supported", c) attrname = c.func.attrname self.write("%s(" % self.get_util_var_name("_super", "%s.helpers.super" % self.lib_name)) self.write("%s, this, '%s')" % (self.exe_node(c.func.expr.args[0]), attrname)) method_written = True if type is None and "type" in self.warnings: logger.warn(" Warning: Cannot infer type [ call: %s, name: %s ] in line %s\n" % (call_type, name, c.lineno )) elif type == "Class": self.write("new ") if not method_written: self.walk(c.func) self.write("(") self.write_call_args(c) self.write(")")
def is_class_method(self, dec): return inference.infer_qname(dec) == "__builtin__.classmethod"
def is_static_method(self, dec): return inference.infer_qname(dec) == "__builtin__.staticmethod"