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)
    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)
 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)
    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)
 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)
 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)
    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)
    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)
    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)
    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)
        self.original = orig
        self.num = 0

    def adaptorFunc(self):
        self.num = self.num + 1
        return self.num, self.original.inc()


class Elapsed(components.Adapter):
    implements(IElapsed)

    def elapsedFunc(self):
        return 1


components.registerAdapter(Adept, Compo, IAdept)
components.registerAdapter(Elapsed, Compo, IElapsed)


class AComp(components.Componentized):
    pass


class BComp(AComp):
    pass


class CComp(BComp):
    pass

Beispiel #12
0
        myPath = FilePath(self.importer.archive)
        itsPath = FilePath(fsPathString)
        if myPath == itsPath:
            return za
        # This is NOT a general-purpose rule for sys.path or __file__:
        # zipimport specifically uses regular OS path syntax in its pathnames,
        # even though zip files specify that slashes are always the separator,
        # regardless of platform.
        segs = itsPath.segmentsFrom(myPath)
        zp = za
        for seg in segs:
            zp = zp.child(seg)
        return zp


registerAdapter(_ZipMapImpl, zipimport.zipimporter, IPathImportMapper)


def _defaultSysPathFactory():
    """
    Provide the default behavior of PythonPath's sys.path factory, which is to
    return the current value of sys.path.

    @return: L{sys.path}
    """
    return sys.path


class PythonPath:
    """
    I represent the very top of the Python object-space, the module list in
Beispiel #13
0
    def jellyFor(self, jellier):
        return reflect.qual(self.__class__), jellier.invoker.registerReference(self)


    def remote_join(self, groupName):
        assert isinstance(groupName, unicode)
        def cbGroup(group):
            def cbJoin(ignored):
                return PBGroup(self.avatar.realm, self.avatar, group)
            d = self.avatar.join(group)
            d.addCallback(cbJoin)
            return d
        d = self.avatar.realm.getGroup(groupName)
        d.addCallback(cbGroup)
        return d
registerAdapter(ChatAvatar, iwords.IUser, pb.IPerspective)

class AvatarReference(pb.RemoteReference):
    def join(self, groupName):
        return self.callRemote('join', groupName)

    def quit(self):
        d = defer.Deferred()
        self.broker.notifyOnDisconnect(lambda: d.callback(None))
        self.broker.transport.loseConnection()
        return d

pb.setUnjellyableForClass(ChatAvatar, AvatarReference)


class WordsRealm(object):
class Adept(components.Adapter):
    implements(IAdept)
    def __init__(self, orig):
        self.original = orig
        self.num = 0
    def adaptorFunc(self):
        self.num = self.num + 1
        return self.num, self.original.inc()

class Elapsed(components.Adapter):
    implements(IElapsed)
    def elapsedFunc(self):
        return 1

components.registerAdapter(Adept, Compo, IAdept)
components.registerAdapter(Elapsed, Compo, IElapsed)

class AComp(components.Componentized):
    pass
class BComp(AComp):
    pass
class CComp(BComp):
    pass

class ITest(Interface):
    pass
class ITest2(Interface):
    pass
class ITest3(Interface):
    pass
Beispiel #15
0

class ProtocolToConsumerAdapter(components.Adapter):
    implements(interfaces.IConsumer)

    def write(self, data):
        self.original.dataReceived(data)

    def registerProducer(self, producer, streaming):
        pass

    def unregisterProducer(self):
        pass


components.registerAdapter(ProtocolToConsumerAdapter, interfaces.IProtocol,
                           interfaces.IConsumer)


class ConsumerToProtocolAdapter(components.Adapter):
    implements(interfaces.IProtocol)

    def dataReceived(self, data):
        self.original.write(data)

    def connectionLost(self, reason):
        pass

    def makeConnection(self, transport):
        pass

    def connectionMade(self):
Beispiel #16
0

class ProtocolToConsumerAdapter(components.Adapter):
    implements(interfaces.IConsumer)

    def write(self, data):
        self.original.dataReceived(data)

    def registerProducer(self, producer, streaming):
        pass

    def unregisterProducer(self):
        pass


components.registerAdapter(ProtocolToConsumerAdapter, interfaces.IProtocol, interfaces.IConsumer)


class ConsumerToProtocolAdapter(components.Adapter):
    implements(interfaces.IProtocol)

    def dataReceived(self, data):
        self.original.write(data)

    def connectionLost(self, reason):
        pass

    def makeConnection(self, transport):
        pass

    def connectionMade(self):
Beispiel #17
0
        myPath = FilePath(self.importer.archive)
        itsPath = FilePath(fsPathString)
        if myPath == itsPath:
            return za
        # This is NOT a general-purpose rule for sys.path or __file__:
        # zipimport specifically uses regular OS path syntax in its pathnames,
        # even though zip files specify that slashes are always the separator,
        # regardless of platform.
        segs = itsPath.segmentsFrom(myPath)
        zp = za
        for seg in segs:
            zp = zp.child(seg)
        return zp


registerAdapter(_ZipMapImpl, zipimport.zipimporter, IPathImportMapper)


def _defaultSysPathFactory():
    """
    Provide the default behavior of PythonPath's sys.path factory, which is to
    return the current value of sys.path.

    @return: L{sys.path}
    """
    return sys.path


class PythonPath:
    """
    I represent the very top of the Python object-space, the module list in