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


Python pyclbr.Class方法代码示例

本文整理汇总了Python中pyclbr.Class方法的典型用法代码示例。如果您正苦于以下问题:Python pyclbr.Class方法的具体用法?Python pyclbr.Class怎么用?Python pyclbr.Class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyclbr的用法示例。


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

示例1: GetSubList

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import Class [as 别名]
def GetSubList(self):
		mod, path = pywin.framework.scriptutils.GetPackageModuleName(self.path)
		win32ui.SetStatusText("Building class list - please wait...", 1)
		win32ui.DoWaitCursor(1)
		try:
			try:
				reader = pyclbr.readmodule_ex # Post 1.5.2 interface.
				extra_msg = " or functions"
			except AttributeError:
				reader = pyclbr.readmodule
				extra_msg = ""
			data = reader(mod, [path])
			if data:
				ret = []
				for item in data.itervalues():
					if item.__class__ != pyclbr.Class: # ie, it is a pyclbr Function instance (only introduced post 1.5.2)
						ret.append(HLICLBRFunction( item, " (function)" ) )
					else:
						ret.append(HLICLBRClass( item, " (class)") )
				ret.sort()
				return ret
			else:
				return [HLIErrorItem("No Python classes%s in module." % (extra_msg,))]
		finally:
			win32ui.DoWaitCursor(0)
			win32ui.SetStatusText(win32ui.LoadString(afxres.AFX_IDS_IDLEMESSAGE)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:browseProjects.py

示例2: GetSubList

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import Class [as 别名]
def GetSubList(self):
        ret = []
        for item in self.clbrdata.itervalues():
            if item.__class__ != pyclbr.Class: # ie, it is a pyclbr Function instance (only introduced post 1.5.2)
                ret.append(HierListCLBRFunction( item ) )
            else:
                ret.append(HierListCLBRClass( item) )
        ret.sort()
        return ret 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:ModuleBrowser.py

示例3: monkey_patch

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import Class [as 别名]
def monkey_patch():
    """If the CONF.monkey_patch set as True,
    this function patches a decorator
    for all functions in specified modules.
    You can set decorators for each modules
    using CONF.monkey_patch_modules.
    The format is "Module path:Decorator function".

    name - name of the function
    function - object of the function
    """
    # If CONF.monkey_patch is not True, this function do nothing.
    if not CONF.monkey_patch:
        return
    if six.PY2:
        is_method = inspect.ismethod
    else:
        def is_method(obj):
            # Unbound methods became regular functions on Python 3
            return inspect.ismethod(obj) or inspect.isfunction(obj)
    # Get list of modules and decorators
    for module_and_decorator in CONF.monkey_patch_modules:
        module, decorator_name = module_and_decorator.split(':')
        # import decorator function
        decorator = importutils.import_class(decorator_name)
        __import__(module)
        # Retrieve module information using pyclbr
        module_data = pyclbr.readmodule_ex(module)
        for key, value in module_data.items():
            # set the decorator for the class methods
            if isinstance(value, pyclbr.Class):
                clz = importutils.import_class("%s.%s" % (module, key))
                for method, func in inspect.getmembers(clz, is_method):
                    setattr(clz, method,
                            decorator("%s.%s.%s" % (module, key,
                                                    method), func))
            # set the decorator for the function
            if isinstance(value, pyclbr.Function):
                func = importutils.import_class("%s.%s" % (module, key))
                setattr(sys.modules[module], key,
                        decorator("%s.%s" % (module, key), func)) 
开发者ID:openstack,项目名称:masakari,代码行数:43,代码来源:utils.py

示例4: get_super_names

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import Class [as 别名]
def get_super_names(cls: pyclbr.Class):
    res = []
    if isinstance(cls.super, list):
        for s in cls.super:
            if isinstance(s, str):
                res.append(s)
            else:
                res.append(s.name)
                res.extend(get_super_names(s))
    elif isinstance(cls.super, pyclbr.Class):
        res.append(cls.super.name)
        res.extend(get_super_names(cls.super))
    elif isinstance(cls, str):
        res.append(cls)
    return res 
开发者ID:lightforever,项目名称:mlcomp,代码行数:17,代码来源:storage.py

示例5: _get_classes_of_module

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import Class [as 别名]
def _get_classes_of_module(module_content):
        classes = dict()  # a dict of 'class_name': pyclbr.Class obj
        for name, obj in module_content.items():
            if isinstance(obj, pyclbr.Class):
                classes[name] = obj
        return classes 
开发者ID:twitter-archive,项目名称:unishark,代码行数:8,代码来源:loader.py

示例6: monkey_patch

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import Class [as 别名]
def monkey_patch():
    """Patch decorator.

    If the Flags.monkey_patch set as True,
    this function patches a decorator
    for all functions in specified modules.
    You can set decorators for each modules
    using CONF.monkey_patch_modules.
    The format is "Module path:Decorator function".
    Example: 'manila.api.ec2.cloud:' \
     manila.openstack.common.notifier.api.notify_decorator'

    Parameters of the decorator is as follows.
    (See manila.openstack.common.notifier.api.notify_decorator)

    name - name of the function
    function - object of the function
    """
    # If CONF.monkey_patch is not True, this function do nothing.
    if not CONF.monkey_patch:
        return
    # Get list of modules and decorators
    for module_and_decorator in CONF.monkey_patch_modules:
        module, decorator_name = module_and_decorator.split(':')
        # import decorator function
        decorator = importutils.import_class(decorator_name)
        __import__(module)
        # Retrieve module information using pyclbr
        module_data = pyclbr.readmodule_ex(module)
        for key in module_data.keys():
            # set the decorator for the class methods
            if isinstance(module_data[key], pyclbr.Class):
                clz = importutils.import_class("%s.%s" % (module, key))
                # NOTE(vponomaryov): we need to distinguish class methods types
                # for py2 and py3, because the concept of 'unbound methods' has
                # been removed from the python3.x
                if six.PY3:
                    member_type = inspect.isfunction
                else:
                    member_type = inspect.ismethod
                for method, func in inspect.getmembers(clz, member_type):
                    setattr(
                        clz, method,
                        decorator("%s.%s.%s" % (module, key, method), func))
            # set the decorator for the function
            if isinstance(module_data[key], pyclbr.Function):
                func = importutils.import_class("%s.%s" % (module, key))
                setattr(sys.modules[module], key,
                        decorator("%s.%s" % (module, key), func)) 
开发者ID:openstack,项目名称:manila,代码行数:51,代码来源:utils.py

示例7: import_executor

# 需要导入模块: import pyclbr [as 别名]
# 或者: from pyclbr import Class [as 别名]
def import_executor(
            self,
            folder: str,
            base_folder: str,
            executor: str,
            libraries: List[Tuple] = None
    ):

        sys.path.insert(0, base_folder)

        spec = self._build_spec(folder)
        was_installation = False

        folders = [
            p for p in glob(f'{folder}/*', recursive=True)
            if os.path.isdir(p) and not spec.match_file(p)
        ]
        folders += [folder]
        library_names = set(n for n, v in (libraries or []))
        library_versions = {n: v for n, v in (libraries or [])}

        for n in library_names:
            try:
                version = pkg_resources.get_distribution(n).version
                need_install = library_versions[n] != version
            except Exception:
                need_install = True

            if INSTALL_DEPENDENCIES and need_install:
                os.system(f'pip install {n}=={library_versions[n]}')
                was_installation = True

        def is_valid_class(cls: pyclbr.Class):
            return cls.name == executor or \
                   cls.name.lower() == executor or \
                   to_snake(cls.name) == executor

        def relative_name(path: str):
            rel = os.path.relpath(path, base_folder)
            parts = [str(p).split('.')[0] for p in rel.split(os.sep)]
            return '.'.join(parts)

        for (module_loader, module_name,
             ispkg) in pkgutil.iter_modules(folders):
            module = module_loader.find_module(module_name)
            rel_path = os.path.relpath(
                os.path.splitext(module.path)[0], base_folder
            ).replace('/', '.')
            try:
                classes = pyclbr.readmodule(rel_path, path=[base_folder])
            except Exception:
                continue
            for k, v in classes.items():
                if is_valid_class(v):
                    importlib.import_module(relative_name(module.path))
                    return True, was_installation

        return False, was_installation 
开发者ID:lightforever,项目名称:mlcomp,代码行数:60,代码来源:storage.py


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