Example #1
0
 def translate_pat_Num(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     comparator = astx.copy_node(pat)
     condition = ast.Compare(left=scrutinee_trans_copy,
                             ops=[ast.Eq()],
                             comparators=[comparator])
     return (condition, _util.odict())
Example #2
0
 def translate_pat_Num(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     comparator = astx.copy_node(pat)
     condition = ast.Compare(
         left=scrutinee_trans_copy,
         ops=[ast.Eq()],
         comparators=[comparator])
     return (condition, _util.odict())
Example #3
0
 def translate_pat_Num(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     comparator = astx.copy_node(pat)
     n = pat.n
     if not isinstance(n, complex):
         comparator.n = complex(n)
     condition = ast.Compare(left=scrutinee_trans_copy,
                             ops=[ast.Eq()],
                             comparators=[comparator])
     return (condition, _util.odict())
Example #4
0
 def translate_pat_Num(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     comparator = astx.copy_node(pat)
     n = pat.n
     if not isinstance(n, complex):
         comparator.n = complex(n)
     condition = ast.Compare(
         left=scrutinee_trans_copy,
         ops=[ast.Eq()],
         comparators=[comparator])
     return (condition, _util.odict())
Example #5
0
    def translate_pat_Call_constructor(self, ctx, pat, scrutinee_trans):
        scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
        args, keywords = pat.args, pat.keywords
        idx = self.idx
        conditions = []
        binding_translations = _util.odict()
        for i, arg in enumerate(args):
            n = _util.odict_idx_of(idx, i)
            elt_scrutinee_trans = astx.make_Subscript_Num_Index(
                scrutinee_trans_copy,
                n)
            elt_condition, elt_binding_translations = ctx.translate_pat(
                arg, elt_scrutinee_trans)
            conditions.append(elt_condition)
            binding_translations.update(elt_binding_translations)
        
        for keyword in keywords:
            n = _util.odict_idx_of(idx, keyword.arg)
            elt_scrutinee_trans = astx.make_Subscript_Num_Index(
                scrutinee_trans_copy,
                n)
            elt_condition, elt_binding_translations = ctx.translate_pat(
                keyword.value, elt_scrutinee_trans)
            conditions.append(elt_condition)
            binding_translations.update(elt_binding_translations)

        condition = ast.BoolOp(
            op=ast.And(),
            values=conditions)

        return (condition, binding_translations)
Example #6
0
 def translate_Compare(self, ctx, e):
     translation = astx.copy_node(e)
     translation.left = ctx.translate(e.left)
     translation.comparators = (
         ctx.translate(comparator)
         for comparator in e.comparators)
     return translation
Example #7
0
    def translate_pat_Call_constructor(self, ctx, pat, scrutinee_trans):
        scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
        args, keywords = pat.args, pat.keywords
        idx = self.idx
        conditions = []
        binding_translations = _util.odict()
        for i, arg in enumerate(args):
            n = _util.odict_idx_of(idx, i)
            elt_scrutinee_trans = astx.make_Subscript_Num_Index(
                scrutinee_trans_copy, n)
            elt_condition, elt_binding_translations = ctx.translate_pat(
                arg, elt_scrutinee_trans)
            conditions.append(elt_condition)
            binding_translations.update(elt_binding_translations)

        for keyword in keywords:
            n = _util.odict_idx_of(idx, keyword.arg)
            elt_scrutinee_trans = astx.make_Subscript_Num_Index(
                scrutinee_trans_copy, n)
            elt_condition, elt_binding_translations = ctx.translate_pat(
                keyword.value, elt_scrutinee_trans)
            conditions.append(elt_condition)
            binding_translations.update(elt_binding_translations)

        condition = ast.BoolOp(op=ast.And(), values=conditions)

        return (condition, binding_translations)
Example #8
0
 def translate_Compare(self, ctx, e):
     translation = astx.copy_node(e)
     translation.left = ctx.translate(e.left)
     translation.comparators = tuple(
         ctx.translate(comparator)
         for comparator in e.comparators)
     return translation
Example #9
0
 def translate_Call(self, ctx, e):
     func, args = e.func, e.args
     translation = astx.copy_node(e)
     translation.func = ctx.translate(func)
     translation.args = list(
         ctx.translate(arg)
         for arg in args)
     return translation
Example #10
0
 def translate_Subscript(self, ctx, e):
     translation = astx.copy_node(e)
     translation.value = ctx.translate(e.value)
     slice_ = e.slice
     slice_translation = astx.copy_node(slice_)
     if isinstance(slice_, ast.Index):
         slice_translation.value = ctx.translate(slice_.value)
     else:
         lower, upper, step = slice_.lower, slice_.upper, slice_.step
         slice_translation.lower = ctx.translate(lower) if lower is not None else None
         slice_translation.upper = ctx.translate(upper) if upper is not None else None
         if not _is_None(step):
             slice_translation.step = ctx.translate(step)
         else:
             slice_translation.step = None
     translation.slice = slice_translation
     return translation 
Example #11
0
 def translate_pat_Tuple(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     elts = pat.elts
     idx = self.idx
     conditions = []
     binding_translations = _util.odict()
     for n, (elt, ty) in enumerate(zip(elts, idx.itervalues())):
         elt_scrutinee_trans = astx.make_Subscript_Num_Index(
             scrutinee_trans_copy, n)
         elt_condition, elt_binding_translations = ctx.translate_pat(
             elt, elt_scrutinee_trans)
         conditions.append(elt_condition)
         binding_translations.update(elt_binding_translations)
     condition = ast.BoolOp(op=ast.And(), values=conditions)
     return (condition, binding_translations)
Example #12
0
 def translate_pat_Dict(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     keys, values = pat.keys, pat.values
     idx = self.idx
     conditions = []
     binding_translations = _util.odict()
     for key, value in zip(keys, values):
         label = key.label
         n = _util.odict_idx_of(idx, label)
         elt_scrutinee_trans = astx.make_Subscript_Num_Index(
             scrutinee_trans_copy, n)
         elt_condition, elt_binding_translations = ctx.translate_pat(
             value, elt_scrutinee_trans)
         conditions.append(elt_condition)
         binding_translations.update(elt_binding_translations)
     condition = ast.BoolOp(op=ast.And(), values=conditions)
     return (condition, binding_translations)
Example #13
0
 def translate_pat_Tuple(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     elts = pat.elts
     idx = self.idx
     conditions = []
     binding_translations = _util.odict()
     for n, (elt, ty) in enumerate(zip(elts, idx.itervalues())):
         elt_scrutinee_trans = astx.make_Subscript_Num_Index(
             scrutinee_trans_copy,
             n)
         elt_condition, elt_binding_translations = ctx.translate_pat(
             elt, elt_scrutinee_trans)
         conditions.append(elt_condition)
         binding_translations.update(elt_binding_translations)
     condition = ast.BoolOp(
         op=ast.And(),
         values=conditions)
     return (condition, binding_translations)
Example #14
0
 def translate_pat_Dict(self, ctx, pat, scrutinee_trans):
     scrutinee_trans_copy = astx.copy_node(scrutinee_trans)
     keys, values = pat.keys, pat.values
     idx = self.idx
     conditions = []
     binding_translations = _util.odict()
     for key, value in zip(keys, values):
         label = key.label
         n = _util.odict_idx_of(idx, label)
         elt_scrutinee_trans = astx.make_Subscript_Num_Index(
             scrutinee_trans_copy,
             n)
         elt_condition, elt_binding_translations = ctx.translate_pat(
             value, elt_scrutinee_trans)
         conditions.append(elt_condition)
         binding_translations.update(elt_binding_translations)
     condition = ast.BoolOp(
         op=ast.And(),
         values=conditions)
     return (condition, binding_translations)
Example #15
0
 def translate_Tuple(self, ctx, e):
     translation = astx.copy_node(e)
     translation.elts = tuple(
         ctx.translate(elt)
         for elt in e.elts)
     return translation 
Example #16
0
 def translate_Num(self, ctx, e):
     return astx.copy_node(e)
Example #17
0
 def translate_Num(self, ctx, e):
     translation = astx.copy_node(e)
     n = e.n
     if not isinstance(n, complex):
         translation.n = complex(n)
     return translation
Example #18
0
 def translate_Num(self, ctx, e):
     translation = astx.copy_node(e)
     translation.n = float(e.n)
     return translation
Example #19
0
 def translate_BinOp(self, ctx, e):
     translation = astx.copy_node(e)
     translation.left = ctx.translate(e.left)
     translation.right = ctx.translate(e.right)
     return translation
Example #20
0
 def translate_UnaryOp(self, ctx, e):
     translation = astx.copy_node(e)
     translation.operand = ctx.translate(e.operand)
     return translation
Example #21
0
 def translate_Attribute(self, ctx, e):
     translation = astx.copy_node(e)
     translation.value = ctx.translate(e.value)
     return translation
Example #22
0
 def translate_Num(self, ctx, e):
     return astx.copy_node(e)
Example #23
0
 def translate_Name(cls, ctx, e):
     translation = astx.copy_node(e)
     translation.id = e.uniq_id
     return translation
Example #24
0
 def translate_BoolOp(self, ctx, e):
     translation = astx.copy_node(e)
     translation.values = tuple(
         ctx.translate(value)
         for value in e.values)
     return translation
Example #25
0
 def translate_UnaryOp(self, ctx, e):
     translation = astx.copy_node(e)
     translation.operand = ctx.translate(e.operand)
     return translation
Example #26
0
 def translate_Attribute(self, ctx, e):
     translation = astx.copy_node(e)
     translation.value = ctx.translate(e.value)
     return translation
Example #27
0
 def translate_Tuple(self, ctx, e):
     translation = astx.copy_node(e)
     translation.elts = tuple(ctx.translate(elt) for elt in e.elts)
     return translation
Example #28
0
 def translate_Num(self, ctx, e):
     translation = astx.copy_node(e)
     translation.n = float(e.n)
     return translation
Example #29
0
 def translate_Num(self, ctx, e):
     translation = astx.copy_node(e)
     n = e.n
     if not isinstance(n, complex):
         translation.n = complex(n)
     return translation
Example #30
0
 def translate_BinOp(self, ctx, e):
     translation = astx.copy_node(e)
     translation.left = ctx.translate(e.left)
     translation.right = ctx.translate(e.right)
     return translation
Example #31
0
 def translate_Name_constructor(self, ctx, e):
     return astx.copy_node(e)