<!--/*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>
                         </div>
                <div>
                        Peter.</div>
                <div>
                         </div>
                <div>
                        On Sun, Jan 13, 2013, at 14:08, Itamar Turner-Trauring wrote:</div>
                <blockquote class="me69157QuoteMessage" type="cite">
                        <div>
                                It'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>
                                 </div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; ">class MultiPortal(object):</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> def __init__(self, portals):</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> self.portals = portals</span></div>
                        <div>
                                 </div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> @inlineCallbacks</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> def login(self, *args, **kwargs):</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> for portal in self.portals:</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> try:</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> return portal.login(*args, **kwargs)</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> except:</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> continue</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> # Ran out of portals, failed to login:</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> raise Unauthorized()</span></div>
                        <div>
                                 </div>
                        <div>
                                Or, let's say you're writing a backend that is a combination checker and realm, where separating that two doesn't make sense. E.g. a backend for a POP3 server that is a proxy to another POP3 server. In this case there's no point in writing separate checker and realm, just write a new Portal:</div>
                        <div>
                                 </div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; ">class POP3ProxyPortal(object):</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> def __init__(self, endpoint):</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> self.endpoint = endpoint</span></div>
                        <div>
                                 </div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> @defer.inlineCallbacks</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> def login(self, credentials, mind, *interfaces):</span><span style="font-family:'courier new',monospace"> </span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> pop3client = yield self.endpoint.connect(POP3ClientFactory())</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> yield pop3client.login(credentials.username, credentials.password)</span></div>
                        <div>
                                <span style="font-family: "courier new"," monospace"; "> defer.returnValue((IMailbox, MailboxProxy(pop3client), pop3client.quit))</span></div>
                        <div>
                                <div>
                                        <br class="me69157Apple-interchange-newline" />
                                         </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>
                        <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>
         </div>
</div></body></html>