當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。