
    )Jf                         g d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
mZ  G d de          Z G d d	e          Zd
 Zd ZdS ))discoverDiscoveryResultDiscoveryFailure    )StringIO)fetchers)YADIS_HEADER_NAMEYADIS_CONTENT_TYPEYADIS_ACCEPT_HEADER)MetaNotFoundfindHTMLMetac                       e Zd ZdZdZd ZdS )r   zBRaised when a YADIS protocol error occurs in the discovery processNc                 J    t                               | |           || _        d S )N)	Exception__init__http_response)selfmessager   s      X/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/yadis/discover.pyr   zDiscoveryFailure.__init__   s&    4)))*    )__name__
__module____qualname____doc__identity_urlr    r   r   r   r      s.        LLL+ + + + +r   r   c                   8    e Zd ZdZdZdZdZdZdZd Z	d Z
d ZdS )r   z:Contains the result of performing Yadis discovery on a URINc                     || _         dS )zgInitialize the state of the object

        sets all attributes to None except the request_uri
        N)request_uri)r   r   s     r   r   zDiscoveryResult.__init__)   s    
 'r   c                 4    | j         dS | j        | j         k    S )z*Was the Yadis protocol's indirection used?NF)xrds_urinormalized_urir   s    r   usedYadisLocationz!DiscoveryResult.usedYadisLocation0   s    = 5"dm33r   c                 J    |                                  p| j        t          k    S )z5Is the response text supposed to be an XRDS document?)r#   content_typer	   r"   s    r   isXRDSzDiscoveryResult.isXRDS6   s'    &&(( 8!%77	9r   )r   r   r   r   r   r!   r    r%   response_textr   r#   r&   r   r   r   r   r      sj        DD K N H L M' ' '4 4 49 9 9 9 9r   r   c                 :   t          |           }t          j        | dt          i          }|j        dvrt          d|j        |          |j        |_        |j        	                    d          |_
        t          |          |_        |j        r{|                                rgt          j        |j                  }|j        dvr&t          d|j        |          }|j        |_        ||j        	                    d          |_
        |j        |_        |S )a  Discover services for a given URI.

    @param uri: The identity URI as a well-formed http or https
        URI. The well-formedness and the protocol are not checked, but
        the results of this function are undefined if those properties
        do not hold.

    @return: DiscoveryResult object

    @raises Exception: Any exception that can be raised by fetching a URL with
        the given fetcher.
    @raises DiscoveryFailure: When the HTTP response does not have a 200 code.
    Accept)headers)      zCHTTP Response status from identity URL host is not 200. Got status content-typez<HTTP Response status from Yadis host is not 200. Got status )r   r   fetchr
   statusr   	final_urlr!   r*   getr%   whereIsYadisr    r#   r   bodyr'   )uriresultrespexcs       r   r   r   <   s&    S!!F>#2E'FGGGD{*$$#{{./35 5 	5
 !NF ,**>::F"4((FO ?63355 ?~fo..;j((""#';;2379 9C  &4CI"l..~>>9FMr   c                    | j                             d          }|r>|                    dd          d                                         t          k    r| j        S | j                             t          j                              }|sZ|pd}|                    dd          }t          |          dk    rb|d         	                                
                    d          r5|d                             dd          d         	                                }nd	}t          | j        t                    rs	 | j                            |          }n^# t          $ rJ 	 | j                            d	          }n+# t          $ r | j                            |d
          }Y nw xY wY nw xY w| j        }	 t!          t#          |                    }n# t$          t          f$ r Y nw xY w|S )zGiven a HTTPResponse, return the location of the Yadis document.

    May be the URL just retrieved, another URL, or None if no suitable URL can
    be found.

    [non-blocking]

    @returns: str or None
    r-   ;   r       zcharset==zutf-8replace)r*   r1   splitlowerr	   r0   r   rsplitlenstrip
startswith
isinstancer3   bytesdecodeUnicodeErrorr   r   r   )r6   r%   	yadis_locencodingcontents        r   r2   r2   h   s	    <##N33L 	 1sA&&q)//115GGG~ L$$%6%<%>%>??	 (	 (-2L#**322HH""QK%%''22:>> ##A;,,S!44Q7==??"$)U++ $H"i..x88GG# H H HH"&)"2"27";";' H H H #')"2"28Y"G"GHH )('):):;;		 ,/    
 sH   5E 
F$E65F$6%FF$FF$#F$/G G G N)__all__ior   openidr   openid.yadis.constantsr   r	   r
   openid.yadis.parsehtmlr   r   r   r   objectr   r   r2   r   r   r   <module>rR      s  
=
=
=            @ @ @ @ @ @ @ @ @ @ = = = = = = = =+ + + + +y + + +#9 #9 #9 #9 #9f #9 #9 #9L) ) )XA A A A Ar   