<!--/*SC*/DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"/*EC*/-->
<html><head><title></title><style type="text/css"><!-- body{padding:1ex;margin:0;font-family:sans-serif;font-size:small}a[href]{color:-moz-hyperlinktext!important;text-decoration:-moz-anchor-decoration}blockquote{margin:0;border-left:2px solid #144fae;padding-left:1em}blockquote blockquote{border-color:#006312}blockquote blockquote blockquote{border-color:#540000} --></style></head><body><div style="font-family: Arial; font-size: medium;" dir="ltr"><div class="defangedMessage">
        <div id="me69157">
                <div>
                        Interesting... those portals could be on different Realms too. It would also allow more than one checker to be tried per interface, which would allow (say) a credentials.IUsernamePassword to be tried against different checkers.</div>
                <div>
                        &nbsp;</div>
                <div>
                        Peter.</div>
                <div>
                        &nbsp;</div>
                <div>
                        On Sun, Jan 13, 2013, at 14:08, Itamar Turner-Trauring wrote:</div>
                <blockquote class="me69157QuoteMessage" type="cite">
                        <div>
                                It&#39;s possible that in some of the cases discussed above, what you want is a custom <span style="font-style: italic">Portal</span>. For example, if you want to try a sequence of logins, and choose the first that succeeds:</div>
                        <div>
                                &nbsp;</div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">class MultiPortal(object):</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; def __init__(self, portals):</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; self.portals = portals</span></div>
                        <div>
                                &nbsp;</div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; @inlineCallbacks</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; def login(self, *args, **kwargs):</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; for portal in self.portals:</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try:</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return portal.login(*args, **kwargs)</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; except:</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; # Ran out of portals, failed to login:</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; raise Unauthorized()</span></div>
                        <div>
                                &nbsp;</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>
                                &nbsp;</div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">class POP3ProxyPortal(object):</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; def __init__(self, endpoint):</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; self.endpoint = endpoint</span></div>
                        <div>
                                &nbsp;</div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; @defer.inlineCallbacks</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; def login(self, credentials, mind, *interfaces):</span><span style="font-family:'courier new',monospace">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; pop3client = yield self.endpoint.connect(POP3ClientFactory())</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; yield pop3client.login(credentials.username, credentials.password)</span></div>
                        <div>
                                <span style="font-family: &quot;courier new&quot;,&quot; monospace&quot;; ">&nbsp; &nbsp; &nbsp; &nbsp; defer.returnValue((IMailbox, MailboxProxy(pop3client), pop3client.quit))</span></div>
                        <div>
                                <div>
                                        <br class="me69157Apple-interchange-newline" />
                                        &nbsp;</div>
                                --&nbsp;<br />
                                Itamar Turner-Trauring, Future Foundries LLC<br />
                                <a href="http://futurefoundries.com/" target="_blank">http://futurefoundries.com/</a>&nbsp;&mdash; Twisted consulting, training and support.</div>
                        <div>
                                <u>_______________________________________________</u></div>
                        <div>
                                Twisted-Python mailing list</div>
                        <div>
                                <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a></div>
                        <div>
                                <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a></div>
                </blockquote>
        </div>
</div>
<div>
        &nbsp;</div>
</div></body></html>