Beispiel #1
0
 def update_value(aname, aval):
     if isinstance(aval, Attribute):
         aval.interface = self
         if not aval.__name__:
             aval.__name__ = aname
     elif isinstance(aval, FunctionType):
         aval = fromFunction(aval, self, name=aname)
     else:
         raise InvalidInterface("Concrete attribute, " + aname)
     return aval
Beispiel #2
0
    def __call__(self, iclass):
        if type(iclass) is not InterfaceClass:
            raise InvalidInterface('%s is not a zope.interface' % iclass)

        if not self.title:
            self.title = iclass.__name__

        gsm = component.getGlobalSiteManager()
        descriptive = ScaffoldingDescriptiveUtility(self.name, iclass,
                                                    self.title)
        gsm.registerUtility(descriptive, IRecipeDescriptive, self.name.lower())
        return iclass
Beispiel #3
0
    def __init__(self,
                 name,
                 bases=(),
                 attrs=None,
                 __doc__=None,
                 __module__=None):

        if attrs is None:
            attrs = {}

        if __module__ is None:
            __module__ = attrs.get('__module__')
            if isinstance(__module__, str):
                del attrs['__module__']
            else:
                try:
                    # Figure out what module defined the interface.
                    # This is how cPython figures out the module of
                    # a class, but of course it does it in C. :-/
                    __module__ = sys._getframe(1).f_globals['__name__']
                except (AttributeError, KeyError):  #pragma NO COVERAGE
                    pass

        self.__module__ = __module__

        d = attrs.get('__doc__')
        if d is not None:
            if not isinstance(d, Attribute):
                if __doc__ is None:
                    __doc__ = d
                del attrs['__doc__']

        if __doc__ is None:
            __doc__ = ''

        Element.__init__(self, name, __doc__)

        tagged_data = attrs.pop(TAGGED_DATA, None)
        if tagged_data is not None:
            for key, val in tagged_data.items():
                self.setTaggedValue(key, val)

        for base in bases:
            if not isinstance(base, InterfaceClass):
                raise TypeError('Expected base interfaces')

        Specification.__init__(self, bases)

        # Make sure that all recorded attributes (and methods) are of type
        # `Attribute` and `Method`
        for name, attr in list(attrs.items()):
            if name in ('__locals__', '__qualname__'):
                # __locals__: Python 3 sometimes adds this.
                # __qualname__: PEP 3155 (Python 3.3+)
                del attrs[name]
                continue
            if isinstance(attr, Attribute):
                attr.interface = self
                if not attr.__name__:
                    attr.__name__ = name
            elif isinstance(attr, FunctionType):
                attrs[name] = fromFunction(attr, self, name=name)
            elif attr is _decorator_non_return:
                del attrs[name]
            else:
                raise InvalidInterface("Concrete attribute, " + name)

        self.__attrs = attrs

        self.__identifier__ = "%s.%s" % (self.__module__, self.__name__)