def import_reg(self, items):
     (identifier, module, __) = items
     if module.value == identifier:
         names = [_ast.alias(name=module.value, asname=None)]
     else:
         names = [_ast.alias(name=module.value, asname=identifier)]
     return _ast.Import(names=names)
    def IMPORT_NAME(self, instr):

        from_ = self.ast_stack.pop()

        hmm = self.ast_stack.pop()

        names = [_ast.alias(name=instr.arg, asname=None)]
        import_ = _ast.Import(names=names, lineno=instr.lineno, col_offset=0)

        import_.from_ = not isNone(from_)

        self.ast_stack.append(import_)
def Import(import_part='', from_part='', asname=None):
    """Creates either an _ast.Import node or an _ast.ImportFrom node.

  Args:
    import_part: The text that follows "import".
    from_part: The text that follows "from". Optional. Determines if we will
      return an _ast.Import or _ast.ImportFrom node.
    asname: Text that follows "as". Optional.

  Returns:
    An _ast.Import or _ast.ImportFrom node.
  """
    names = [_ast.alias(name=import_part, asname=asname)]
    if from_part:
        return _ast.ImportFrom(level=0, module=from_part, names=names)
    else:
        return _ast.Import(names=names)
Exemple #4
0
def build_import():
    module = menu('module')['module']
    add_ast_node(_ast.Import(names=[_ast.alias(name=module, asname=None)]))
Exemple #5
0
 def visit_Module(self, module_node):
     module_node.body.insert(
         0, _ast.Import(names=[_ast.alias(name='unittest')]))
     return module_node