コード例 #1
0
 def _multipleInterfacesForClassOrInterface(self, original):
     adapter = lambda o: None
     class FirstInterface(Interface):
         pass
     class SecondInterface(Interface):
         pass
     components.registerAdapter(adapter, original, FirstInterface, SecondInterface)
     self.assertIdentical(
         components.getAdapterFactory(original, FirstInterface, None),
         adapter)
     self.assertIdentical(
         components.getAdapterFactory(original, SecondInterface, None),
         adapter)
コード例 #2
0
 def _subclassAdapterRegistrationForClassOrInterface(self, original):
     firstAdapter = lambda o: True
     secondAdapter = lambda o: False
     class TheSubclass(original):
         pass
     class TheInterface(Interface):
         pass
     components.registerAdapter(firstAdapter, original, TheInterface)
     components.registerAdapter(secondAdapter, TheSubclass, TheInterface)
     self.assertIdentical(
         components.getAdapterFactory(original, TheInterface, None),
         firstAdapter)
     self.assertIdentical(
         components.getAdapterFactory(TheSubclass, TheInterface, None),
         secondAdapter)
コード例 #3
0
ファイル: plugin.py プロジェクト: Hetal728/SMP-ClassiCube
 def __conform__(self, interface, registry=None, default=None):
     for providedInterface in self.provided:
         if providedInterface.isOrExtends(interface):
             return self.load()
         if getAdapterFactory(providedInterface, interface, None) is not None:
             return interface(self.load(), default)
     return default
コード例 #4
0
    def _multipleInterfacesForClassOrInterface(self, original):
        adapter = lambda o: None

        class FirstInterface(Interface):
            pass

        class SecondInterface(Interface):
            pass

        components.registerAdapter(adapter, original, FirstInterface,
                                   SecondInterface)
        self.assertIdentical(
            components.getAdapterFactory(original, FirstInterface, None),
            adapter)
        self.assertIdentical(
            components.getAdapterFactory(original, SecondInterface, None),
            adapter)
コード例 #5
0
 def _registerAdapterForClassOrInterface(self, original):
     adapter = lambda o: None
     class TheInterface(Interface):
         pass
     components.registerAdapter(adapter, original, TheInterface)
     self.assertIdentical(
         components.getAdapterFactory(original, TheInterface, None),
         adapter)
コード例 #6
0
ファイル: plugin.py プロジェクト: Hetal728/SMP-ClassiCube
 def __conform__(self, interface, registry=None, default=None):
     for providedInterface in self.provided:
         if providedInterface.isOrExtends(interface):
             return self.load()
         if getAdapterFactory(providedInterface, interface,
                              None) is not None:
             return interface(self.load(), default)
     return default
コード例 #7
0
    def _subclassAdapterRegistrationForClassOrInterface(self, original):
        firstAdapter = lambda o: True
        secondAdapter = lambda o: False

        class TheSubclass(original):
            pass

        class TheInterface(Interface):
            pass

        components.registerAdapter(firstAdapter, original, TheInterface)
        components.registerAdapter(secondAdapter, TheSubclass, TheInterface)
        self.assertIdentical(
            components.getAdapterFactory(original, TheInterface, None),
            firstAdapter)
        self.assertIdentical(
            components.getAdapterFactory(TheSubclass, TheInterface, None),
            secondAdapter)
コード例 #8
0
    def _registerAdapterForClassOrInterface(self, original):
        adapter = lambda o: None

        class TheInterface(Interface):
            pass

        components.registerAdapter(adapter, original, TheInterface)
        self.assertIdentical(
            components.getAdapterFactory(original, TheInterface, None),
            adapter)
コード例 #9
0
    def _duplicateAdapterForClassOrInterface(self, original):
        firstAdapter = lambda o: False
        secondAdapter = lambda o: True

        class TheInterface(Interface):
            pass

        components.registerAdapter(firstAdapter, original, TheInterface)
        self.assertRaises(ValueError, components.registerAdapter,
                          secondAdapter, original, TheInterface)
        # Make sure that the original adapter is still around as well
        self.assertIdentical(
            components.getAdapterFactory(original, TheInterface, None),
            firstAdapter)
コード例 #10
0
 def _duplicateAdapterForClassOrInterface(self, original):
     firstAdapter = lambda o: False
     secondAdapter = lambda o: True
     class TheInterface(Interface):
         pass
     components.registerAdapter(firstAdapter, original, TheInterface)
     self.assertRaises(
         ValueError,
         components.registerAdapter,
         secondAdapter, original, TheInterface)
     # Make sure that the original adapter is still around as well
     self.assertIdentical(
         components.getAdapterFactory(original, TheInterface, None),
         firstAdapter)
コード例 #11
0
    def _duplicateAdapterForClassOrInterfaceAllowed(self, original):
        firstAdapter = lambda o: False
        secondAdapter = lambda o: True

        class TheInterface(Interface):
            pass

        components.registerAdapter(firstAdapter, original, TheInterface)
        components.ALLOW_DUPLICATES = True
        try:
            components.registerAdapter(secondAdapter, original, TheInterface)
            self.assertIdentical(
                components.getAdapterFactory(original, TheInterface, None),
                secondAdapter)
        finally:
            components.ALLOW_DUPLICATES = False

        # It should be rejected again at this point
        self.assertRaises(ValueError, components.registerAdapter, firstAdapter,
                          original, TheInterface)

        self.assertIdentical(
            components.getAdapterFactory(original, TheInterface, None),
            secondAdapter)
コード例 #12
0
    def _duplicateAdapterForClassOrInterfaceAllowed(self, original):
        firstAdapter = lambda o: False
        secondAdapter = lambda o: True
        class TheInterface(Interface):
            pass
        components.registerAdapter(firstAdapter, original, TheInterface)
        components.ALLOW_DUPLICATES = True
        try:
            components.registerAdapter(secondAdapter, original, TheInterface)
            self.assertIdentical(
                components.getAdapterFactory(original, TheInterface, None),
                secondAdapter)
        finally:
            components.ALLOW_DUPLICATES = False

        # It should be rejected again at this point
        self.assertRaises(
            ValueError,
            components.registerAdapter,
            firstAdapter, original, TheInterface)

        self.assertIdentical(
            components.getAdapterFactory(original, TheInterface, None),
            secondAdapter)