
    f                         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y))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y)r   zBRaised when a YADIS protocol error occurs in the discovery processNc                 >    t         j                  | |       || _        y )N)	Exception__init__http_response)selfmessager   s      P/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/openid/yadis/discover.pyr   zDiscoveryFailure.__init__   s    4)*    )__name__
__module____qualname____doc__identity_urlr    r   r   r   r      s    LL+r   r   c                   6    e Zd ZdZdZdZdZdZdZd Z	d Z
d Zy)r   z:Contains the result of performing Yadis discovery on a URINc                     || _         y)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                 N    | j                   y| j                  | j                   k7  S )z*Was the Yadis protocol's indirection used?F)xrds_urinormalized_urir   s    r   usedYadisLocationz!DiscoveryResult.usedYadisLocation0   s$    == ""dmm33r   c                 L    | j                         xs | 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      s7    D K N H L M'49r   r   c                 r   t        |       }t        j                  | dt        i      }|j                  dvrt        d|j                  |      |j                  |_        |j                  j                  d      |_
        t        |      |_        |j                  r|j                         ryt        j                  |j                        }|j                  dvr,t        d|j                  |      }|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GD{{*$#{{./35 	5
 !NNF ,,**>:F"4(FO6335~~foo.;;j("#';;2379C  &44CI"ll..~>99FMr   c                 z   | j                   j                  d      }|r6|j                  dd      d   j                         t        k(  r| j
                  S | j                   j                  t        j                               }|s|xs d}|j                  dd      }t        |      dk(  rI|d   j                         j                  d      r'|d   j                  dd      d   j                         }nd	}t        | j                  t              r	 | j                  j                  |      }n| j                  }	 t!        t#        |            }|S |S # t        $ rK 	 | j                  j                  d	      }n+# t        $ r | j                  j                  |d
      }Y nw xY wY lw xY w# t$        t        f$ r Y |S w xY w)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3L 	sA&q)//15GG~~ LL$$%6%<%<%>?	 (-2L#**32HH"QK%%'22:>#A;,,S!4Q7==?"$))U+H"ii..x8G ))('):;	 y/ $ HH"&))"2"27";' H #'))"2"28Y"GHH$ !,/  sH   E 8F' 	F$E65F$6%FF$FF$#F$'F:9F:N)__all__ior   openidr   openid.yadis.constantsr   r	   r
   openid.yadis.parsehtmlr   r   r   r   objectr   r   r2   r   r   r   <module>rR      sD   
=  @ @ =+y +#9f #9L)XAr   