<s> """<STR_LIT>""" <EOL> import binascii <EOL> from zope . interface import implements <EOL> from twisted . cred import credentials , error <EOL> from twisted . web . iweb import ICredentialFactory <EOL> class BasicCredentialFactory ( object ) : <EOL> """<STR_LIT>""" <EOL> implements ( ICredentialFactory ) <EOL> scheme = '<STR_LIT>' <EOL> def __init__ ( self , authenticationRealm ) : <EOL> self . authenticationRealm = authenticationRealm <EOL> def getChallenge ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return { '<STR_LIT>' : self . authenticationRealm } <EOL> def decode ( self , response , request ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> creds = binascii . a2b_base64 ( response + '<STR_LIT>' ) <EOL> except binascii . Error : <EOL> raise error . LoginFailed ( '<STR_LIT>' ) <EOL> creds = creds . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if len ( creds ) == <NUM_LIT:2> : <EOL> return credentials . UsernamePassword ( * creds ) <EOL> else : <EOL> raise error . LoginFailed ( '<STR_LIT>' ) </s>
