<s> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> from cStringIO import StringIO <EOL> from openid import fetchers <EOL> from openid . yadis . constants import YADIS_HEADER_NAME , YADIS_CONTENT_TYPE , YADIS_ACCEPT_HEADER <EOL> from openid . yadis . parsehtml import MetaNotFound , findHTMLMeta <EOL> class DiscoveryFailure ( Exception ) : <EOL> """<STR_LIT>""" <EOL> identity_url = None <EOL> def __init__ ( self , message , http_response ) : <EOL> Exception . __init__ ( self , message ) <EOL> self . http_response = http_response <EOL> class DiscoveryResult ( object ) : <EOL> """<STR_LIT>""" <EOL> request_uri = None <EOL> normalized_uri = None <EOL> xrds_uri = None <EOL> content_type = None <EOL> response_text = None <EOL> def __init__ ( self , request_uri ) : <EOL> """<STR_LIT>""" <EOL> self . request_uri = request_uri <EOL> def usedYadisLocation ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . normalized_uri != self . xrds_uri <EOL> def isXRDS ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( self . usedYadisLocation ( ) or <EOL> self . content_type == YADIS_CONTENT_TYPE ) <EOL> def discover ( uri ) : <EOL> """<STR_LIT>""" <EOL> result = DiscoveryResult ( uri ) <EOL> resp = fetchers . fetch ( uri , headers = { '<STR_LIT>' : YADIS_ACCEPT_HEADER } ) <EOL> if resp . status not in ( <NUM_LIT:200> , <NUM_LIT> ) : <EOL> raise DiscoveryFailure ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( resp . status , ) , resp ) <EOL> result . normalized_uri = resp . final_url <EOL> result . content_type = resp . headers . get ( '<STR_LIT>' ) <EOL> result . xrds_uri = whereIsYadis ( resp ) <EOL> if result . xrds_uri and result . usedYadisLocation ( ) : <EOL> resp = fetchers . fetch ( result . xrds_uri ) <EOL> if resp . status not in ( <NUM_LIT:200> , <NUM_LIT> ) : <EOL> exc = DiscoveryFailure ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( resp . status , ) , resp ) <EOL> exc . identity_url = result . normalized_uri <EOL> raise exc <EOL> result . content_type = resp . headers . get ( '<STR_LIT>' ) <EOL> result . response_text = resp . body <EOL> return result <EOL> def whereIsYadis ( resp ) : <EOL> """<STR_LIT>""" <EOL> content_type = resp . headers . get ( '<STR_LIT>' ) <EOL> if ( content_type and <EOL> content_type . split ( '<STR_LIT:;>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . lower ( ) == YADIS_CONTENT_TYPE ) : <EOL> return resp . final_url <EOL> else : <EOL> yadis_loc = resp . headers . get ( YADIS_HEADER_NAME . lower ( ) ) <EOL> if not yadis_loc : <EOL> try : <EOL> yadis_loc = findHTMLMeta ( StringIO ( resp . body ) ) <EOL> except MetaNotFound : <EOL> pass <EOL> return yadis_loc </s>
