当前位置: 首页>>代码示例>>Python>>正文


Python manager.ASTNGManager类代码示例

本文整理汇总了Python中logilab.astng.manager.ASTNGManager的典型用法代码示例。如果您正苦于以下问题:Python ASTNGManager类的具体用法?Python ASTNGManager怎么用?Python ASTNGManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ASTNGManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: brainless_manager

 def brainless_manager(self):
     manager = ASTNGManager()
     # avoid caching into the ASTNGManager borg since we get problems
     # with other tests :
     manager.__dict__ = {}
     manager.astng_cache = {}
     manager._mod_file_cache = {}
     return manager
开发者ID:Chaos99,项目名称:cachetools,代码行数:8,代码来源:unittest_regrtest.py

示例2: test_borg

    def test_borg(self):
        """test that the ASTNGManager is really a borg, i.e. that two different
        instances has same cache"""
        first_manager = ASTNGManager()
        built = first_manager.astng_from_module_name(BUILTINS_NAME)

        second_manager = ASTNGManager()
        second_built = first_manager.astng_from_module_name(BUILTINS_NAME)
        self.assertTrue(built is second_built)
开发者ID:OFFIS-Automation,项目名称:Framework,代码行数:9,代码来源:unittest_manager.py

示例3: __init__

 def __init__(self, args):
     ConfigurationMixIn.__init__(self, usage=__doc__)
     insert_default_options()
     self.manager = ASTNGManager()
     self.register_options_provider(self.manager)
     args = self.load_command_line_configuration()
     self.run(args)
开发者ID:bmcharek,项目名称:opendata101-workshops,代码行数:7,代码来源:main.py

示例4: PyreverseCommand

class PyreverseCommand(ConfigurationMixIn):
    """base class providing common behaviour for pyreverse commands"""

    options = OPTIONS

    def __init__(self, args):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        insert_default_options()
        self.manager = ASTNGManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        self.run(args)

    def run(self, args):
        """checking arguments and run project"""
        if not args:
            print(self.help())
            return
        # insert current working directory to the python path to recognize
        # dependencies to local modules even if cwd is not in the PYTHONPATH
        sys.path.insert(0, os.getcwd())
        try:
            project = self.manager.project_from_files(args)
            linker = Linker(project, tag=True)
            handler = DiadefsHandler(self.config)
            diadefs = handler.get_diadefs(project, linker)
        finally:
            sys.path.pop(0)

        if self.config.output_format == "vcg":
            writer.VCGWriter(self.config).write(diadefs)
        else:
            writer.DotWriter(self.config).write(diadefs)
开发者ID:OFFIS-Automation,项目名称:Framework,代码行数:33,代码来源:main.py

示例5: PyreverseCommand

class PyreverseCommand(ConfigurationMixIn):
    """base class providing common behaviour for pyreverse commands"""

    options = OPTIONS

    def __init__(self, args):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        insert_default_options()
        self.manager = ASTNGManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        self.run(args)

    def run(self, args):
        """checking argmuents and run project"""
        if not args:
            print self.help()
            return
        project = self.manager.project_from_files(args, astng_wrapper)
        linker = Linker(project, tag=True)
        handler = DiadefsHandler(self.config)
        diadefs = handler.get_diadefs(project, linker)
        if self.config.output_format == "vcg":
            writer.VCGWriter(self.config).write(diadefs)
        else:
            writer.DotWriter(self.config).write(diadefs)
开发者ID:bmcharek,项目名称:opendata101-workshops,代码行数:26,代码来源:main.py

示例6: __init__

 def __init__(self, args):
     ConfigurationMixIn.__init__(self, usage=__doc__)
     insert_default_options()
     self.manager = ASTNGManager()
     self.register_options_provider(self.manager)
     args = self.load_command_line_configuration()
     project = self.manager.project_from_files(args, astng_wrapper)
     self.project = project
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:8,代码来源:astng.py

示例7: __init__

 def __init__(self, view, args, callback):
     ConfigurationMixIn.__init__(self, usage=__doc__)
     insert_default_options()
     self.manager = ASTNGManager()
     self.register_options_provider(self.manager)
     self.view = view
     self.callback = callback
     self.run(args)
开发者ID:jvorcak,项目名称:gpylint,代码行数:8,代码来源:scanner.py

示例8: __init__

 def __init__(self, args,process_candidates=False):
     ConfigurationMixIn.__init__(self, usage=__doc__)
     self._prob_used_classes = Set([])
     self._dbg_assattr_parents = Set([])
     self._process_candidates = process_candidates
     insert_default_options()
     self.manager = ASTNGManager()
     self.register_options_provider(self.manager)
     args = self.load_command_line_configuration()
     self.run(args)
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:10,代码来源:obsolete.py

示例9: __init__

 def __init__(self, args,criteria='default',out_file='test.xml',treshold=None,add_value=False):
     ConfigurationMixIn.__init__(self, usage=__doc__)
     self._add_value = add_value
     self._project = args[0]
     self._treshold = treshold
     self._out_file = out_file
     self._criteria = criteria
     self._dbg_assattr_parents = set([])
     insert_default_options()
     self.manager = ASTNGManager()
     self.register_options_provider(self.manager)
     args = self.load_command_line_configuration()
     self.run(args)
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:13,代码来源:builder.py

示例10: ScannerCommand

class ScannerCommand(ConfigurationMixIn):
    """base class providing common behaviour for pyreverse commands"""

    options = OPTIONS

    def __init__(self, view, args, callback):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        insert_default_options()
        self.manager = ASTNGManager()
        self.register_options_provider(self.manager)
        self.view = view
        self.callback = callback
        self.run(args)

    def run(self, args):
        """checking arguments and run project"""
        if not args:
            print self.help()
            return
        # insert current working directory to the python path to recognize
        # dependencies to local modules even if cwd is not in the PYTHONPATH
        sys.path.insert(0, args[0])
        sys.path.insert(0, os.getcwd())

        try:
            project = self.manager.project_from_files(args, black_list= \
                    map(os.path.relpath, BlackList.blacklist))
            linker = Linker(project, tag=True)
            handler = DiadefsHandler(self.config)
            diadefs = handler.get_diadefs(project, linker)
        finally:
            sys.path.pop(0)

        # filter just classes (not packages) for now
        diadefs = filter(lambda x: x.TYPE == 'class', diadefs)

        # update GUI
        Gdk.threads_enter()
        self.callback()
        writer.CanvasWriter(self.view, self.config).write(diadefs)
        Gdk.threads_leave()
开发者ID:jvorcak,项目名称:gpylint,代码行数:41,代码来源:scanner.py

示例11: LogilabUCRBuilder

class LogilabUCRBuilder(ConfigurationMixIn):
    ''' generate XML, describing classes of project '''
    
    options = OPTIONS
    
    _good_gettatr = 0
    _bad_gettatr = 0
    # numbers of "ducks" in project (for complexity estimation)
    _all_ducks = 0
    # numbers of classes in project (for complexity estimation)
    _all_classes = 0
    _process_candidates = False
    _ducks_count = 0
    _found_ducks = 0
    _prob_used_classes = None
    _all_attrs_num = 0
    _complex_ducks = 0
    _assigned_ducks = 0
    _dbg_assattr_parents = None 
    _list_attrs = [attr for attr in dir([]) if not re.search('\A(?!_)',attr)]
    _list_methods = [attr for attr in dir([]) if re.search('\A(?!_)',attr)]
    _dict_attrs = [attr for attr in dir({}) if not re.search('\A(?!_)',attr)]
    _dict_methods = [attr for attr in dir({}) if re.search('\A(?!_)',attr)]
    _tuple_attrs = [attr for attr in dir(()) if not re.search('\A(?!_)',attr)]
    _tuple_methods = [attr for attr in dir(()) if re.search('\A(?!_)',attr)]
    _attr_iteration_cycles = 0
    _processed_methods = 0
    
    def __init__(self, args,process_candidates=False):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        self._prob_used_classes = Set([])
        self._dbg_assattr_parents = Set([])
        self._process_candidates = process_candidates
        insert_default_options()
        self.manager = ASTNGManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        self.run(args)
      
    """ Extract information about class signature - attrs and methods, which it have """    
    def _compute_signature(self,node):
        if(hasattr(node, "csu_complete_signatures")):
            # node have been processed already
            return node.csu_complete_signatures
        else:
            node.csu_complete_signatures={}
        node.csu_complete_signatures['Attrs'] = Set([re.search('[^ :]*',attr).group(0) for attr in node.attrs])
        node.csu_complete_signatures['Methods'] = Set([meth.name for meth in node.methods])
        # class without parents
        if not hasattr(node, "csu_parents"):
            node.csu_parents = []
        parents = node.csu_parents
        for parent in parents:
            parent_signature = self._compute_signature(parent)
            # append all parents signatures
            node.csu_complete_signatures['Attrs'] |= parent_signature['Attrs']
            node.csu_complete_signatures['Methods'] |= parent_signature['Methods']
        return node.csu_complete_signatures
    
    """ Check body of cycle, which iterating over class's field"""
    def _check_cycle(self,node,iter_name,attr,duck_dict):
        if isinstance(node, Getattr):
            if(node.expr.as_string()==iter_name):
                if(not duck_dict[attr].has_key('element_signature')):
                           duck_dict[attr]['element_signature']={'attrs':Set([]),'methods':Set([])} 
                if isinstance(node.parent,CallFunc):
                    duck_dict[attr]['element_signature']['methods'].add(node.attrname)
                else:
                    duck_dict[attr]['element_signature']['attrs'].add(node.attrname)           
        for child in node.get_children():
            duck_dict = self._check_cycle(child,iter_name,attr,duck_dict)
        return duck_dict
    
    """ Extract information about class fields usage """
    def _extract_duck_info(self,node,attrs,duck_dict=None):
        if(duck_dict is None):
            duck_dict = {}
        if isinstance(node, Getattr):
            if(node.expr.as_string()=="self"):
                if isinstance(node.parent, For):
                    if(not duck_dict.has_key(node.attrname)):
                        self._ducks_count +=1
                        duck_dict[node.attrname] = {'attrs':Set([]),'methods':Set([]),'type':[],'complex_type':'Unknown','assigned':False}
                    self._attr_iteration_cycles +=1
                    if isinstance(node.parent.target, AssName):
                        print node.parent.as_string()
                        for body in node.parent.body:
                            duck_dict = self._check_cycle(body,node.parent.target.name,node.attrname,duck_dict)
                if(node.attrname not in attrs):
                    #print node.attrname,node.parent, node.fromlineno, node.root()
                    #print attrs
                    self._bad_gettatr+=1
                else:
                    self._good_gettatr+=1
                # if additional info about attr's field may be obtained
                if isinstance(node.parent, Getattr):
                    #init dict for attr
                    if(not duck_dict.has_key(node.attrname)):
                        self._ducks_count +=1
                        duck_dict[node.attrname] = {'attrs':Set([]),'methods':Set([]),'type':[],'complex_type':None,'assigned':False}
#.........这里部分代码省略.........
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:101,代码来源:obsolete.py

示例12: import

"""

__docformat__ = "restructuredtext en"

import sys
from os.path import abspath
from inspect import (getargspec, isdatadescriptor, isfunction, ismethod,
                     ismethoddescriptor, isclass, isbuiltin)

from logilab.astng import BUILTINS_MODULE
from logilab.astng.node_classes import CONST_CLS
from logilab.astng.nodes import (Module, Class, Const, const_factory, From,
    Function, EmptyNode, Name, Arguments, Dict, List, Set, Tuple)
from logilab.astng.bases import Generator
from logilab.astng.manager import ASTNGManager
MANAGER = ASTNGManager()

_CONSTANTS = tuple(CONST_CLS) # the keys of CONST_CLS eg python builtin types

def _attach_local_node(parent, node, name):
    node.name = name # needed by add_local_node
    parent.add_local_node(node)

_marker = object()

def attach_dummy_node(node, name, object=_marker):
    """create a dummy node and register it in the locals of the given
    node with the specified name
    """
    enode = EmptyNode()
    enode.object = object
开发者ID:daviewales,项目名称:pylint-mode,代码行数:31,代码来源:raw_building.py

示例13: UCRBuilder

class UCRBuilder(ConfigurationMixIn,DuckTypeHandler):
    # generate XML, describing classes of project
    
    options = OPTIONS
    
    # criteria for duck typing
    _criteria = None
    _out_file = None
    _project = None
    _good_gettatr = 0
    _bad_gettatr = 0
    # numbers of "ducks" in project (for complexity estimation)
    _all_ducks = 0
    # numbers of classes in project (for complexity estimation)
    _all_classes = 0
#     _found_ducks = 0
    _prob_used_classes = None
    _dbg_assattr_parents = None 
    _list_attrs = [attr for attr in dir([]) if not re.search('\A(?!_)',attr)]
    _list_methods = [attr for attr in dir([]) if re.search('\A(?!_)',attr)]
    _dict_attrs = [attr for attr in dir({}) if not re.search('\A(?!_)',attr)]
    _dict_methods = [attr for attr in dir({}) if re.search('\A(?!_)',attr)]
    _tuple_attrs = [attr for attr in dir(()) if not re.search('\A(?!_)',attr)]
    _tuple_methods = [attr for attr in dir(()) if re.search('\A(?!_)',attr)]
    _attr_iteration_cycles = 0
    _treshold = None
    _add_value = None
    
    def __init__(self, args,criteria='default',out_file='test.xml',treshold=None,add_value=False):
        ConfigurationMixIn.__init__(self, usage=__doc__)
        self._add_value = add_value
        self._project = args[0]
        self._treshold = treshold
        self._out_file = out_file
        self._criteria = criteria
        self._dbg_assattr_parents = set([])
        insert_default_options()
        self.manager = ASTNGManager()
        self.register_options_provider(self.manager)
        args = self.load_command_line_configuration()
        self.run(args)
    
    # Check if object is of standard complex type(dict, tuple or list)
    def _check_complex_type(self,attrs,methods):
        if(all(meth in self._list_methods for meth in methods) and
           all(attr in self._list_attrs for attr in attrs)):
            return 'List'
        elif(all(meth in self._dict_methods for meth in methods) and
             all(attr in self._dict_attrs for attr in attrs)):
            return 'Dict'
        elif(all(meth in self._tuple_methods for meth in methods) and
             all(attr in self._tuple_attrs for attr in attrs)):
            return 'Tuple'
        return None
    
    def get_duck_signature(self,duck):
        if(duck['complex_type']):
            if duck.has_key('element_signature'):
                # search for class of element is needed
                return set(duck['element_signature']['attrs'].keys()),set(duck['element_signature']['methods'].keys())
        return set(duck['attrs'].keys()), set(duck['methods'].keys())

    def run(self, args):
        """checking arguments and run project"""
        if not args:
            print self.help()
            return
        project = self.manager.project_from_files(args, astng_wrapper)
        self.project = project
        linker = ClassIRLinker(project)
        linker.visit(project)
        if self._criteria == 'capacity':
            found_ducks = {}
            bad_ducks = {}
            prob_used_classes = {}
            for t in numpy.arange(self._treshold,1,0.05):
                found_ducks[t] = 0
                bad_ducks[t] = 0
                prob_used_classes[t] = set([])
        else:
            prob_used_classes = set([])
            bad_ducks = 0
            found_ducks = 0
        ducks_num = len(list(linker.get_ducks()))
        count = 1
        dbg = set([])
        empty_ducks = 0
        """ Handle "duck" information and generate information about types """
        for current_class in linker.get_classes():
            for duck in current_class.cir_ducks.keys():
                print "Processing ", count, " duck of ",ducks_num
#                 print duck,current_class.cir_ducks[duck]
                count +=1
                duck_attrs, duck_methods = self.get_duck_signature(current_class.cir_ducks[duck])
                """ ignore empty ducks """
                if((not duck_attrs) and (not duck_methods)):
                    empty_ducks+=1
                    continue
                if not hasattr(current_class.cir_ducks[duck], 'complex_type'):
                    """ if duck is not detected  as complex type on previous stage (according to [],{} etc. usage)
#.........这里部分代码省略.........
开发者ID:exbluesbreaker,项目名称:csu-code-analysis,代码行数:101,代码来源:builder.py

示例14: setUp

 def setUp(self):
     self.manager = ASTNGManager(borg=False)
开发者ID:AndryulE,项目名称:kitsune,代码行数:2,代码来源:unittest_manager.py

示例15: ASTNGManagerTC

class ASTNGManagerTC(unittest.TestCase):
    def setUp(self):
        self.manager = ASTNGManager(borg=False)
        
    def test_astng_from_module(self):
        astng = self.manager.astng_from_module(unittest)
        self.assertEquals(astng.pure_python, True)
        import time
        astng = self.manager.astng_from_module(time)
        self.assertEquals(astng.pure_python, False)
        
    def test_astng_from_class(self):
        astng = self.manager.astng_from_class(file)
        self.assertEquals(astng.name, 'file')
        self.assertEquals(astng.parent.frame().name, '__builtin__')

        astng = self.manager.astng_from_class(object)
        self.assertEquals(astng.name, 'object')
        self.assertEquals(astng.parent.frame().name, '__builtin__')
        self.failUnless('__setattr__' in astng)
        
    def _test_astng_from_zip(self, archive):
        origpath = sys.path[:]
        sys.modules.pop('mypypa', None)
        sys.path.insert(0, join(dirname(__file__), 'data', archive))
        try:
            module = self.manager.astng_from_module_name('mypypa')
            self.assertEquals(module.name, 'mypypa')
            self.failUnless(module.file.endswith('%s/mypypa' % archive),
                            module.file)
        finally:
            sys.path = origpath

    def test_astng_from_module_name_egg(self):
        self._test_astng_from_zip('MyPyPa-0.1.0-py2.5.egg')

    def test_astng_from_module_name_zip(self):
        self._test_astng_from_zip('MyPyPa-0.1.0-py2.5.zip')            
        
    def test_from_directory(self):
        obj = self.manager.from_directory('data')
        self.assertEquals(obj.name, 'data')
        self.assertEquals(obj.path, join(os.getcwd(), 'data'))
        
    def test_package_node(self):
        obj = self.manager.from_directory('data')
        expected_short = ['SSL1', '__init__', 'all', 'appl', 'format', 'module', 'module2',
                          'noendingnewline', 'nonregr', 'notall']
        expected_long = ['SSL1', 'data', 'data.all', 'appl', 'data.format', 'data.module',
                         'data.module2', 'data.noendingnewline', 'data.nonregr',
                         'data.notall']
        self.assertEquals(obj.keys(), expected_short)
        self.assertEquals([m.name for m in obj.values()], expected_long)
        self.assertEquals([m for m in list(obj)], expected_short)
        self.assertEquals([(name, m.name) for name, m in obj.items()],
                          zip(expected_short, expected_long))
        self.assertEquals([(name, m.name) for name, m in obj.items()],
                          zip(expected_short, expected_long))
        
        self.assertEquals('module' in obj, True)
        self.assertEquals(obj.has_key('module'), True)
        self.assertEquals(obj.get('module').name, 'data.module')
        self.assertEquals(obj['module'].name, 'data.module')
        self.assertEquals(obj.get('whatever'), None)
        self.assertEquals(obj.fullname(), 'data')
开发者ID:AndryulE,项目名称:kitsune,代码行数:65,代码来源:unittest_manager.py


注:本文中的logilab.astng.manager.ASTNGManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。