def testClasses(self):
     components.fixClassImplements(Sub)
     components.fixClassImplements(MultiplyAndAdd)
     self.assert_( IMultiply.implementedBy(MultiplyAndAdd) )
     self.assert_( IAdder.implementedBy(MultiplyAndAdd) )
     self.assert_( IAdder.implementedBy(Sub) )
     self.assert_( ISub.implementedBy(Sub) )
示例#2
0
    def __init__(self, m, templateFile=None, templateDirectory=None, template=None, controller=None, doneCallback=None, modelStack=None, viewStack=None, controllerStack=None):
        """
        A view must be told what its model is, and may be told what its
        controller is, but can also look up its controller if none specified.
        """
        components.fixClassImplements(m.__class__)
        if not interfaces.IModel.providedBy(m):
            m = model.adaptToIModel(m, None, None)
        self.model = self.mainModel = m
        # It's the responsibility of the calling code to make sure
        # setController is called on this view before it's rendered.
        self.controller = None
        self.subviews = {}
        if self.setupStacks:
            self.modelStack = None
            self.viewStack = None
            self.controllerStack = None
            if doneCallback is None and self.doneCallback is None:
                self.doneCallback = doSendPage
            else:
                print "DoneCallback", doneCallback
                self.doneCallback = doneCallback
        if template is not None:
            self.template = template
        if templateFile is not None:
            self.templateFile = templateFile
        if templateDirectory is not None:
            self.templateDirectory = templateDirectory

        self.outstandingCallbacks = 0
        self.outstandingNodes = []
        self.failed = 0
        self.setupMethods = []
示例#3
0
    def login(self, credentials, mind, *interfaces):
        """
        @param credentials: an implementor of
        twisted.cred.credentials.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.
        """
        components.fixClassImplements(credentials.__class__)
        ifac = interface.providedBy(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)))))
示例#4
0
    def login(self, credentials, mind, *interfaces):
        """
        @param credentials: an implementor of
        twisted.cred.credentials.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.
        """
        components.fixClassImplements(credentials.__class__)
        ifac = interface.providedBy(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)))))
示例#5
0
    def __init__(self,
                 m,
                 templateFile=None,
                 templateDirectory=None,
                 template=None,
                 controller=None,
                 doneCallback=None,
                 modelStack=None,
                 viewStack=None,
                 controllerStack=None):
        """
        A view must be told what its model is, and may be told what its
        controller is, but can also look up its controller if none specified.
        """
        components.fixClassImplements(m.__class__)
        if not interfaces.IModel.providedBy(m):
            m = model.adaptToIModel(m, None, None)
        self.model = self.mainModel = m
        # It's the responsibility of the calling code to make sure
        # setController is called on this view before it's rendered.
        self.controller = None
        self.subviews = {}
        if self.setupStacks:
            self.modelStack = None
            self.viewStack = None
            self.controllerStack = None
            if doneCallback is None and self.doneCallback is None:
                self.doneCallback = doSendPage
            else:
                print "DoneCallback", doneCallback
                self.doneCallback = doneCallback
        if template is not None:
            self.template = template
        if templateFile is not None:
            self.templateFile = templateFile
        if templateDirectory is not None:
            self.templateDirectory = templateDirectory

        self.outstandingCallbacks = 0
        self.outstandingNodes = []
        self.failed = 0
        self.setupMethods = []