<s> """<STR_LIT>""" <EOL> from twisted . internet import defer <EOL> from twisted . internet . defer import maybeDeferred <EOL> from twisted . python import failure , reflect <EOL> from twisted . cred import error <EOL> from zope . interface import providedBy , Interface <EOL> class IRealm ( Interface ) : <EOL> """<STR_LIT>""" <EOL> def requestAvatar ( avatarId , mind , * interfaces ) : <EOL> """<STR_LIT>""" <EOL> class Portal : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , realm , checkers = ( ) ) : <EOL> """<STR_LIT>""" <EOL> self . realm = realm <EOL> self . checkers = { } <EOL> for checker in checkers : <EOL> self . registerChecker ( checker ) <EOL> def listCredentialsInterfaces ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . checkers . keys ( ) <EOL> def registerChecker ( self , checker , * credentialInterfaces ) : <EOL> if not credentialInterfaces : <EOL> credentialInterfaces = checker . credentialInterfaces <EOL> for credentialInterface in credentialInterfaces : <EOL> self . checkers [ credentialInterface ] = checker <EOL> def login ( self , credentials , mind , * interfaces ) : <EOL> """<STR_LIT>""" <EOL> for i in self . checkers : <EOL> if i . providedBy ( credentials ) : <EOL> return maybeDeferred ( self . checkers [ i ] . requestAvatarId , credentials <EOL> ) . addCallback ( self . realm . requestAvatar , mind , * interfaces <EOL> ) <EOL> ifac = providedBy ( credentials ) <EOL> return defer . fail ( failure . Failure ( error . UnhandledCredentials ( <EOL> "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( map ( reflect . qual , ifac ) ) ) ) ) </s>
