Example #1
0
    def analyze(self, source, old_module=None):
        """Analyze the source provided and create the proper structure."""
        astModule = self._get_valid_module(source)
        if astModule is None:
            return model.Module()
        self.content = source.split('\n')

        module = model.Module()
        for symbol in astModule.body:
            if symbol.__class__ is ast.Assign:
                assigns = self._process_assign(symbol)[0]
                module.add_attributes(assigns)
            elif symbol.__class__ in (ast.Import, ast.ImportFrom):
                module.add_imports(self._process_import(symbol))
            elif symbol.__class__ is ast.ClassDef:
                module.add_class(self._process_class(symbol))
            elif symbol.__class__ is ast.FunctionDef:
                module.add_function(self._process_function(symbol))
#            elif symbol.__class__ is ast.Expr:
#                self._process_expression(symbol.value)
        if old_module is not None:
            self._resolve_module(module, old_module)

        self.content = None
        #        self._functions = {}
        return module
Example #2
0
 def analyze(self, astmodule):
     self.module = model.Module()
     self.visit(astmodule)