def testVerifyImplementation(self):
     from zope.interface.verify import verifyClass
     from zope.interface import Interface
     from zope.interface.tests.unitfixtures import Foo
     from zope.interface.tests.unitfixtures import FooInterface
     from zope.interface.tests.unitfixtures import I1
     self.assert_(verifyClass(FooInterface, Foo))
     self.assert_(Interface.providedBy(I1))
 def testVerifyImplementation(self):
     from zope.interface.verify import verifyClass
     from zope.interface import Interface
     from zope.interface.tests.unitfixtures import Foo
     from zope.interface.tests.unitfixtures import FooInterface
     from zope.interface.tests.unitfixtures import I1
     self.assert_(verifyClass(FooInterface, Foo))
     self.assert_(Interface.providedBy(I1))
Beispiel #3
0
def load_cached_schema():
    for x in get_utilities_for(IResourceFactory):
        factory = x[1]
        if factory.type_name not in SCHEMA_CACHE:
            FACTORY_CACHE[factory.type_name] = factory
            behaviors_registrations = []
            for iface in factory.behaviors or ():
                if Interface.providedBy(iface):
                    name = iface.__identifier__
                else:
                    name = iface
                behaviors_registrations.append(get_utility(IBehavior, name=name))
            SCHEMA_CACHE[factory.type_name] = {"behaviors": behaviors_registrations, "schema": factory.schema}
    for iface, utility in get_utilities_for(IBehavior):
        if isinstance(iface, str):
            name = iface
        elif Interface.providedBy(iface):
            name = iface.__identifier__
        if name not in BEHAVIOR_CACHE:
            BEHAVIOR_CACHE[name] = utility.interface
Beispiel #4
0
def load_cached_schema():
    for x in getUtilitiesFor(IResourceFactory):
        factory = x[1]
        if factory.portal_type not in SCHEMA_CACHE:
            behaviors_registrations = []
            for iface in factory.behaviors or ():
                if Interface.providedBy(iface):
                    name = iface.__identifier__
                else:
                    name = iface
                behaviors_registrations.append(getUtility(IBehavior, name=name))
            SCHEMA_CACHE[factory.portal_type] = {
                'behaviors': behaviors_registrations,
                'schema': factory.schema
            }
    for iface, utility in getUtilitiesFor(IBehavior):
        if isinstance(iface, str):
            name = iface
        elif Interface.providedBy(iface):
            name = iface.__identifier__
        if name not in BEHAVIOR_CACHE:
            BEHAVIOR_CACHE[name] = utility.interface
Beispiel #5
0
    def remove_behavior(self, iface):
        """We need to apply the marker interface.

        value: Interface to add
        """
        if isinstance(iface, str):
            name = iface
        elif Interface.providedBy(iface):
            name = iface.__identifier__
        behavior_registration = getUtility(IBehavior, name=name)
        if behavior_registration is not None and\
                behavior_registration.marker is not None:
            noLongerProvides(self, behavior_registration.marker)
        if iface in self.__behaviors__:
            self.__behaviors__ -= {name}
Beispiel #6
0
    def remove_behavior(self, iface):
        """We need to apply the marker interface.

        value: Interface to add
        """
        if isinstance(iface, str):
            name = iface
        elif Interface.providedBy(iface):
            name = iface.__identifier__
        behavior_registration = getUtility(IBehavior, name=name)
        if behavior_registration is not None and\
                behavior_registration.marker is not None:
            noLongerProvides(self, behavior_registration.marker)
        if iface in self.__behaviors__:
            self.__behaviors__ -= {name}
Beispiel #7
0
def export_fields_to_dict(obj, fields=None, parentname=None):
    export_dict = {'name': obj.name, 'title': obj.title, 'ref': obj.paco_ref_parts}
    if schemas.IDeployable.providedBy(obj):
        export_dict['enabled'] = obj.is_enabled()
    if fields != None:
        for fieldname in fields:
            value = getattr(obj, fieldname, None)
            if value == None or value == '':
                continue
            if Interface.providedBy(value):
                if not isinstance(value, (str, int, float, list)):
                    value = auto_export_obj_to_dict(value)
            export_dict[fieldname] = value
    if parentname != None:
        export_dict[parentname] = obj.__parent__.name
    return export_dict
Beispiel #8
0
    def add_behavior(self, iface):
        """We need to apply the marker interface.

        value: Interface to add
        """
        if isinstance(iface, str):
            name = iface
        elif Interface.providedBy(iface):
            name = iface.__identifier__
        else:
            raise AttributeError('Cant identify Interface')
        behavior_registration = getUtility(IBehavior, name=name)
        if behavior_registration is not None and\
                behavior_registration.interface(self) is not None:
            # We can adapt so we can apply this dynamic behavior
            self.__behaviors__ |= {name}
            if behavior_registration.marker is not None:
                alsoProvides(self, behavior_registration.marker)
Beispiel #9
0
    def add_behavior(self, iface):
        """We need to apply the marker interface.

        value: Interface to add
        """
        if isinstance(iface, str):
            name = iface
        elif Interface.providedBy(iface):
            name = iface.__identifier__
        else:
            raise AttributeError('Cant identify Interface')
        behavior_registration = getUtility(IBehavior, name=name)
        if behavior_registration is not None and\
                behavior_registration.interface(self) is not None:
            # We can adapt so we can apply this dynamic behavior
            self.__behaviors__ |= {name}
            if behavior_registration.marker is not None:
                alsoProvides(self, behavior_registration.marker)
Beispiel #10
0
    def remove_behavior(self, iface: Union[str, Interface]) -> None:
        """We need to apply the marker interface.

        value: Interface to add
        """
        if isinstance(iface, str):
            name = iface
        elif Interface.providedBy(iface):
            name = iface.__identifier__  # type: ignore
        behavior_registration = get_utility(IBehavior, name=name)
        if behavior_registration is not None and behavior_registration.marker is not None:
            try:
                noLongerProvides(self, behavior_registration.marker)
            except ValueError:
                # could not remove interface
                pass
        if iface in self.__behaviors__:
            self.__behaviors__ -= {name}
        self.register()  # make sure we resave this obj
Beispiel #11
0
    def add_behavior(self, iface: Union[str, Interface]) -> None:
        """We need to apply the marker interface.

        value: Interface to add
        """
        if isinstance(iface, str):
            name = iface
        elif Interface.providedBy(iface):
            name = iface.__identifier__  # type: ignore
        else:
            raise AttributeError("Cant identify Interface")
        behavior_registration = get_utility(IBehavior, name=name)
        if behavior_registration is not None and behavior_registration.interface(self) is not None:
            # We can adapt so we can apply this dynamic behavior
            if name not in self.__behaviors__:
                self.__behaviors__ |= {name}
                if behavior_registration.marker is not None:
                    alsoProvides(self, behavior_registration.marker)
                self.register()  # make sure we resave this obj
 def testVerifyImplementation(self):
     from zope.interface.verify import verifyClass
     self.assert_(verifyClass(FooInterface, Foo))
     self.assert_(Interface.providedBy(I1))
Beispiel #13
0
 def testVerifyImplementation(self):
     from zope.interface.verify import verifyClass
     self.assert_(verifyClass(FooInterface, Foo))
     self.assert_(Interface.providedBy(I1))