コード例 #1
0
 def com_NEWLINE(self, *args):
     # A ';' at the end of a line can make a NEWLINE token appear
     # here, Render it harmless. (genc discards ('discard',
     # ('const', xxxx)) Nodes)
     lineno = args[0][1]
     # don't put fromlineno/tolineno on Const None to mark it as dynamically
     # added, without "physical" reference in the source
     n = nodes.Discard(nodes.Const(None))
     n.fromlineno = n.tolineno = lineno
     return n
コード例 #2
0
 def visit_module(self, node):
     """visit a stmt.Module node -> init node and push the corresponding
     object or None on the top of the stack
     """
     self._stack = [self._module]
     self._par_stack = [node]
     self._metaclass = ['']
     self._global_names = []
     node.parent = None
     node.globals = node.locals = {}
     for name, value in (('__name__', node.name), ('__file__', node.path),
                         ('__doc__', node.doc)):
         const = nodes.Const(value)
         const.parent = node
         node.locals[name] = [const]
     attach___dict__(node)
     if node.package:
         # FIXME: List(Const())
         const = nodes.Const(dirname(node.path))
         const.parent = node
         node.locals['__path__'] = [const]
コード例 #3
0
 def visit_class(self, node):
     """visit a stmt.Class node -> init node and push the corresponding
     object or None on the top of the stack
     """
     self.visit_default(node)
     node.instance_attrs = {}
     node.basenames = [b_node for b_node in node.bases]
     self._push(node)
     for name, value in (('__name__', node.name),
                         ('__module__', node.root().name), ('__doc__',
                                                            node.doc)):
         const = nodes.Const(value)
         const.parent = node
         node.locals[name] = [const]
     attach___dict__(node)
     self._metaclass.append(self._metaclass[-1])
コード例 #4
0
def build_class(name, basenames=None, doc=None):
    """create and initialize a astng Class node"""
    klass = nodes.Class(name, [], doc, nodes.Stmt([]))
    bases = [nodes.Name(base) for base in basenames]
    for base in bases:
        base.parent = klass
    klass.basenames = basenames
    klass.bases = bases
    klass.code.parent = klass
    klass.locals = {}
    klass.instance_attrs = {}
    for name, value in (('__name__', name),
                        #('__module__', node.root().name),
                        ):
        const = nodes.Const(value)
        const.parent = klass
        klass.locals[name] = [const]
    return klass
コード例 #5
0
def attach_const_node(node, name, value):
    """create a Const node and register it in the locals of the given
    node with the specified name
    """
    _attach_local_node(node, nodes.Const(value), name)
コード例 #6
0
def build_attr_assign(name, value, attr='self'):
    """create and initialize an astng Assign for an attribute assignment"""
    return nodes.Assign([nodes.AssAttr(nodes.Name(attr), name, 'OP_ASSIGN')],
                        nodes.Const(value))
コード例 #7
0
def build_name_assign(name, value):
    """create and initialize an astng Assign for a name assignment"""
    return nodes.Assign([nodes.AssName(name, 'OP_ASSIGN')], nodes.Const(value))