o
    gf]                     @   sx   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 deZG dd	 d	eZd
d Zdd ZdS ))discoverDiscoveryResultDiscoveryFailure    )StringIO)fetchers)YADIS_HEADER_NAMEYADIS_CONTENT_TYPEYADIS_ACCEPT_HEADER)MetaNotFoundfindHTMLMetac                   @   s   e Zd ZdZdZdd ZdS )r   zBRaised when a YADIS protocol error occurs in the discovery processNc                 C   s   t | | || _d S )N)	Exception__init__http_response)selfmessager    r   V/var/www/html/humari/django-venv/lib/python3.10/site-packages/openid/yadis/discover.pyr      s   
zDiscoveryFailure.__init__)__name__
__module____qualname____doc__identity_urlr   r   r   r   r   r      s    r   c                   @   s<   e Zd ZdZdZdZdZdZdZdd Z	dd Z
dd ZdS )	r   z:Contains the result of performing Yadis discovery on a URINc                 C   s
   || _ dS )zgInitialize the state of the object

        sets all attributes to None except the request_uri
        N)request_uri)r   r   r   r   r   r   '   s   
zDiscoveryResult.__init__c                 C   s   | j | jkS )z*Was the Yadis protocol's indirection used?)normalized_urixrds_urir   r   r   r   usedYadisLocation.   s   z!DiscoveryResult.usedYadisLocationc                 C   s   |   p| jtkS )z5Is the response text supposed to be an XRDS document?)r   content_typer   r   r   r   r   isXRDS2   s   zDiscoveryResult.isXRDS)r   r   r   r   r   r   r   r   response_textr   r   r   r   r   r   r   r      s    r   c                 C   s   t | }tj| dtid}|jdvrtd|jf ||j|_|j	d|_
t||_|jrS| rSt|j}|jdvrLtd|jf |}|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)      zEHTTP Response status from identity URL host is not 200. Got status %rcontent-typez>HTTP Response status from Yadis host is not 200. Got status %r)r   r   fetchr	   statusr   	final_urlr   r!   getr   whereIsYadisr   r   r   bodyr   )uriresultrespexcr   r   r   r   7   s4   


r   c                 C   sp   | j d}|r|ddd  tkr| jS | j t }|s6z
tt| j	}W |S  t
y5   Y |S w |S )zGiven a HTTPResponse, return the location of the Yadis document.

    May be the URL just retrieved, another URL, or None, if I can't
    find any.

    [non-blocking]

    @returns: str or None
    r$   ;   r   )r!   r(   splitlowerr   r'   r   r   r   r*   r
   )r-   r   	yadis_locr   r   r   r)   d   s   r)   N)__all__	cStringIOr   openidr   openid.yadis.constantsr   r   r	   openid.yadis.parsehtmlr
   r   r   r   objectr   r   r)   r   r   r   r   <module>   s   #-