Ejemplo n.º 1
0
 def assigns(self):
     return Parser(
         None,
         [
             flatten(node)
             for node in self.execute("$.body[@.type is 'Assign']").n
         ],
     )
Ejemplo n.º 2
0
 def last_line(self):
     return flatten(self.nodes["body"][-1])
Ejemplo n.º 3
0
 def query_raw(self, pattern):
     nodes = Template(pattern).process(self.code, True)
     if isinstance(nodes, list) and len(nodes) == 1:
         nodes = [flatten(convert_node(node)) for node in nodes[0].body]
     return Parser(None, nodes)
Ejemplo n.º 4
0
 def for_(self):
     for_body = self.execute("$.body[@.type is 'For'].body").n
     iterators = self.execute("$.body[@.type is 'For'].(target, iter)").n
     return Parser(None, [flatten(for_body), flatten(iterators)])
Ejemplo n.º 5
0
 def returns_call(self):
     return Parser(None,
                   [flatten(self.execute("$.body[@.type is 'Return']").n)])
Ejemplo n.º 6
0
 def decorators(self):
     return Parser(None, [flatten(self.execute("$.decorator_list").n)])
Ejemplo n.º 7
0
 def assign_(self):
     return Parser(None,
                   [flatten(self.execute("$.body[@.type is 'Assign']").n)])
Ejemplo n.º 8
0
    def calls(self):
        nodes = self.execute(
            "$.body[@.type is 'Expr' and @.value.type is 'Call']").n
        node_list = [nodes] if isinstance(nodes, dict) else nodes

        return Parser(None, [flatten(node) for node in node_list])
Ejemplo n.º 9
0
 def assign_to(self):
     nodes = self.execute("$.body[@.type is 'Assign']").n
     if isinstance(nodes, dict):
         return Parser(None, [flatten(nodes)])
     else:
         return Parser(None, [flatten(node) for node in nodes])