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


Python InterfaceClass.__new__方法代码示例

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


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

示例1: __new__

# 需要导入模块: from zope.interface.interface import InterfaceClass [as 别名]
# 或者: from zope.interface.interface.InterfaceClass import __new__ [as 别名]
    def __new__(cls, name, bases, dct):
        rv = cls = InterfaceClass.__new__(cls)
        cls.__id__ = nextId()
        cls.__methods__ = methods = []
        cls.__properties__ = properties = []
        cls.default = 'DEFAULT'
        cls.complexType = True
        possibleActions = []
        actionAttachers = []
        for key, value in list(dct.items()):
            if key[0] == '_': continue

            if isinstance(value, MetaTypedInterface):
                ## A Nested TypedInterface indicates a GroupBinding
                properties.append(GroupBinding(key, value, value.__id__))

                ## zope.interface doesn't like these
                del dct[key]
                setattr(cls, key, value)
            elif isinstance(value, collections.Callable):
                names, _, _, typeList = inspect.getargspec(value)

                _testCallArgs = ()

                if typeList is None:
                    typeList = []

                if len(names) == len(typeList) + 1:
                    warnings.warn(
                        "TypeInterface method declarations should not have a 'self' parameter",
                        DeprecationWarning,
                        stacklevel=2)
                    del names[0]
                    _testCallArgs = (_Marker,)

                if len(names) != len(typeList):
                    ## Allow non-autocallable methods in the interface; ignore them
                    continue

                argumentTypes = [
                    Argument(n, argtype, argtype.id) for n, argtype in zip(names[-len(typeList):], typeList)
                ]

                result = value(*_testCallArgs)

                label = None
                description = None
                if getattr(value, 'autocallable', None):
                    # autocallables have attributes that can set label and description
                    label = value.attributes.get('label', None)
                    description = value.attributes.get('description', None)

                adapted = iformless.ITyped(result, None)
                if adapted is None:
                    adapted = Object(result)

                # ITyped has label and description we can use
                if label is None:
                    label = adapted.label
                if description is None:
                    description = adapted.description

                defaultLabel, defaultDescription = labelAndDescriptionFromDocstring(value.__doc__)
                if defaultLabel is None:
                    # docstring had no label, try the action if it is an autocallable
                    if getattr(value, 'autocallable', None):
                        if label is None and value.action is not None:
                            # no explicit label, but autocallable has action we can use
                            defaultLabel = value.action

                if defaultLabel is None:
                    # final fallback: use the function name as label
                    defaultLabel = nameToLabel(key)

                if label is None:
                    label = defaultLabel
                if description is None:
                    description = defaultDescription

                theMethod = Method(
                    adapted, argumentTypes, label=label, description=description
                )

                if getattr(value, 'autocallable', None):
                    methods.append(
                        MethodBinding(
                            key, theMethod, value.id, value.action, value.attributes))
                else:
                    possibleActions.append((value, MethodBinding(key, theMethod)))
            else:
                if not value.label:
                    value.label = nameToLabel(key)
                if iformless.IActionableType.providedBy(value):
                    actionAttachers.append(value)
                properties.append(
                    Property(key, value, value.id)
                )
        for attacher in actionAttachers:
            attacher.attachActionBindings(possibleActions)
        methods.sort(key=_sorter)
#.........这里部分代码省略.........
开发者ID:perkinslr,项目名称:nevow-py3,代码行数:103,代码来源:annotate.py


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