<div>It&#39;s possible that in some of the cases discussed above, what you want is a custom <i>Portal</i>. For example, if you want to try a sequence of logins, and choose the first that succeeds:</div><div><br></div><div>

<font face="courier new, monospace">class MultiPortal(object):</font></div><div><font face="courier new, monospace">    def __init__(self, portals):</font></div><div><font face="courier new, monospace">        self.portals = portals</font></div>

<div><br></div><div><font face="courier new, monospace">    @inlineCallbacks</font></div><div><font face="courier new, monospace">    def login(self, *args, **kwargs):</font></div>
<div><font face="courier new, monospace">        for portal in self.portals:</font></div><div><font face="courier new, monospace">            try:</font></div><div><font face="courier new, monospace">                return portal.login(*args, **kwargs)</font></div>

<div><font face="courier new, monospace">            except:</font></div><div><font face="courier new, monospace">                continue</font></div><div><font face="courier new, monospace">        # Ran out of portals, failed to login:</font></div>

<div><font face="courier new, monospace">        raise Unauthorized()</font></div><div><br></div><div>Or, let&#39;s say you&#39;re writing a backend that is a combination checker and realm, where separating that two doesn&#39;t make sense. E.g. a backend for a POP3 server that is a proxy to another POP3 server. In this case there&#39;s no point in writing separate checker and realm, just write a new Portal:</div>

<div><br></div><div><font face="courier new, monospace">class POP3ProxyPortal(object):</font></div><div><font face="courier new, monospace">    def __init__(self, endpoint):</font></div><div><font face="courier new, monospace">        self.endpoint = endpoint</font></div>

<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">    @defer.inlineCallbacks</font></div><div><font face="courier new, monospace">    def login(self, credentials, mind, *interfaces):</font><span style="font-family:&#39;courier new&#39;,monospace">        </span></div>

<div><font face="courier new, monospace">        pop3client = yield self.endpoint.connect(POP3ClientFactory())</font></div><div><font face="courier new, monospace">        yield pop3client.login(credentials.username, credentials.password)</font></div>

<div><font face="courier new, monospace">        defer.returnValue((IMailbox, MailboxProxy(pop3client), pop3client.quit))</font></div><div><div><br class="Apple-interchange-newline"><br></div>-- <br>Itamar Turner-Trauring, Future Foundries LLC<br>
<a href="http://futurefoundries.com/" target="_blank">http://futurefoundries.com/</a> — Twisted consulting, training and support.</div>