Example #1
0
 def testGetInterfaces(self):
     l = components.getInterfaces(Sub)
     l.sort()
     l2 = [IAdder, ISub]
     l2.sort()
     self.assertEquals(l, l2)
     l = components.getInterfaces(MultiplyAndAdd)
     l.sort()
     l2 = [IAdder, IMultiply]
     l2.sort()
     self.assertEquals(l, l2)
Example #2
0
    def testGetInterfaces(self):
        l = components.getInterfaces(Sub)
        l.sort()
        l2 = [IAdder, ISub]
        l2.sort()
        self.assertEquals(l, l2)

        l = components.getInterfaces(MultiplyAndAdd)
        l.sort()
        l2 = [IAdder, IMultiply]
        l2.sort()
        self.assertEquals(l, l2)
Example #3
0
def registerFactory(configurableClass, factory):
    """Register a factory for a class."""
    factories[configurableClass] = factory
    for i in components.getInterfaces(configurableClass):
        if interfaceImplementors.has_key(i):
            interfaceImplementors[i].append(configurableClass)
        else:
            interfaceImplementors[i] = [configurableClass]
Example #4
0
 def requestAvatarId(self, credentials):
     ifac = components.getInterfaces(credentials)
     for i in ifac:
         c = self.checkers.get(i)
         if c is not None:
             return c.requestAvatarId(credentials).addCallback(
                 self._cbGoodAuthentication, credentials)
     return defer.fail(UnhandledCredentials("No checker for %s" % \
         ', '.join(map(reflect.qal, ifac))))
Example #5
0
    def login(self, credentials, mind, *interfaces):
        """    
        @param credentials: an implementor of
        twisted.cred.interfaces.ICredentials

        @param mind: an object which implements a client-side interface for
        your particular realm.  In many cases, this may be None, so if the word
        'mind' confuses you, just ignore it.

        @param interfaces: list of interfaces for the perspective that the mind
        wishes to attach to.  Usually, this will be only one interface, for
        example IMailAccount.  For highly dynamic protocols, however, this may
        be a list like (IMailAccount, IUserChooser, IServiceInfo).  To expand:
        if we are speaking to the system over IMAP, any information that will
        be relayed to the user MUST be returned as an IMailAccount implementor;
        IMAP clients would not be able to understand anything else.  Any
        information about unusual status would have to be relayed as a single
        mail message in an otherwise-empty mailbox.  However, in a web-based
        mail system, or a PB-based client, the ``mind'' object inside the web
        server (implemented with a dynamic page-viewing mechanism such as
        woven) or on the user's client program may be intelligent enough to
        respond to several ``server''-side interfaces.

        @return: A deferred which will fire a tuple of (interface,
        avatarAspect, logout).  The interface will be one of the interfaces
        passed in the 'interfaces' argument.  The 'avatarAspect' will implement
        that interface.  The 'logout' object is a callable which will detach
        the mind from the avatar.  It must be called when the user has
        conceptually disconnected from the service.  Although in some cases
        this will not be in connectionLost (such as in a web-based session), it
        will always be at the end of a user's interactive session.
        """
        ifac = components.getInterfaces(credentials)
        for i in ifac:
            c = self.checkers.get(i)
            if c is not None:
                return maybeDeferred(c.requestAvatarId, credentials
                    ).addCallback(self.realm.requestAvatar, mind, *interfaces
                    )
        return defer.fail(failure.Failure(error.UnhandledCredentials(
            "No checker for %s" % ' ,'.join(map(reflect.qual, ifac)))))
Example #6
0
 def providedBy(obj):
     """ Hi!  I'm Troy McLure, you might remember me from such films as 'Don't Use
     Twisted.Python.Components', and 'Seriously, Don't Use
     Twisted.Python.Components, You Jackass'.  This function simulates Zope
     Interface's providedBy on a _very_ rudimentary level.  It might return
     stuff in a totally different order than ZI, but execution/adaptation
     order is one of those things which, if it is important to your
     application, you need to be using zope.interface directly anyway and
     this flimsy compatibility layer won't be enough.  """
     oclass = getattr(obj, '__class__',
                      types.ClassType)
     implementedByClass = list(getInterfaces(oclass))
     providedByClassT = getattr(oclass, '__provides__', ())
     providedByMeT = getattr(obj, '__provides__', ())
     if providedByMeT is providedByClassT:
         providedByMe = []
     else:
         providedByMe = list(providedByMeT)
     for x in implementedByClass + providedByMe:
         if x is not ITwistedHack:
             yield x