
    qh.?                     >   S r / SQrSSKrSSKrSSKJrJr  SSKJr  SSK	J
r
JrJr  SSKJr  SSKJr  SS	KJr  SS
KJrJr  SSKJr  SSKJr  SrSrSrSrSrSSKJ r!  SSKJ"r#  \RH                  " \%5      r& " S S\'5      r(S r)S r*S r+S r,S r-S r.S r/S r0S r1S rg) z9Functions to discover OpenID endpoints from identifiers.
)DiscoveryFailureOPENID_1_0_NSOPENID_1_0_TYPEOPENID_1_1_TYPEOPENID_2_0_TYPEOPENID_IDP_2_0_TYPEOpenIDServiceEndpointdiscover    N)fetchersurinorm)yadis)nsTag	XRDSError
XRD_NS_2_0)applyFilter)r	   )r   )xriresfiltersxri)
html_parsezhttp://openid.net/xmlns/1.0z'http://specs.openid.net/auth/2.0/serverz'http://specs.openid.net/auth/2.0/signonzhttp://openid.net/signon/1.1zhttp://openid.net/signon/1.0)
OPENID1_NS)
OPENID2_NSc                       \ rS rSrSr\\\\/r	S r
S rS rS rS rS rS	 rS
 rS rS r\" \5      rS r\" \5      rS r\" \5      rS r\" \5      rS r\" \5      rS rSrg)r   +   zObject representing an OpenID service endpoint.

@ivar identity_url: the verified identifier.
@ivar canonicalID: For XRI, the persistent identifier.
c                 f    S U l         S U l        / U l        S U l        S U l        SU l        S U l        g )NF)
claimed_id
server_url	type_urislocal_idcanonicalID
used_yadisdisplay_identifierselfs    J/var/www/html/env/lib/python3.13/site-packages/openid/consumer/discover.py__init__OpenIDServiceEndpoint.__init__;   s5    "&    c                     XR                   ;   $ N)r   )r$   extension_uris     r%   usesExtension#OpenIDServiceEndpoint.usesExtensionD   s    ..r(   c                 j    [         U R                  ;   d  [        U R                  ;   a  [        $ [        $ r*   )r   r   r   OPENID_2_0_MESSAGE_NSOPENID_1_0_MESSAGE_NSr#   s    r%   preferredNamespace(OpenIDServiceEndpoint.preferredNamespaceG   s&    4>>14>>1((((r(   c                 l    XR                   ;   =(       d     U[        :H  =(       a    U R                  5       $ )ziDoes this endpoint support this type?

I consider C{/server} endpoints to implicitly support C{/signon}.
)r   r   isOPIdentifier)r$   type_uris     r%   supportsType"OpenIDServiceEndpoint.supportsTypeN   s0    
 ^^+ H_,F1D1D1F	Ir(   c                     U R                   b  U R                   $ U R                  c  g[        R                  R	                  U R                  5      S   $ )zJReturn the display_identifier if set, else return the claimed_id.
        Nr
   )r"   r   urllibparse	urldefragr#   s    r%   getDisplayIdentifier*OpenIDServiceEndpoint.getDisplayIdentifierV   sG     "".***??"<<))$//:1==r(   c                 0    U R                  5       [        :g  $ r*   )r1   r/   r#   s    r%   compatibilityMode'OpenIDServiceEndpoint.compatibilityMode`   s    &&(,AAAr(   c                 (    [         U R                  ;   $ r*   )r   r   r#   s    r%   r4   $OpenIDServiceEndpoint.isOPIdentifierc   s    "dnn44r(   c                     X0l         X l        SU l        U R                  5       (       d"  [	        UU R                   5      U l        Xl        gg)zJSet the state of this object based on the contents of the
service element.TN)r   r   r!   r4   findOPLocalIdentifierr   r   )r$   	yadis_urlurir   service_elements        r%   parseService"OpenIDServiceEndpoint.parseServicef   sF     #""$$
 2/26..BDM'O %r(   c                     U R                   U R                  s=L a  c   U R                  $   U R                   =(       d    U R                  $ )zYReturn the identifier that should be sent as the
openid.identity parameter to the server.)r   r    r   r#   s    r%   
getLocalID OpenIDServiceEndpoint.getLocalIDv   s<     MMT--5??" 6 ==4D$4$44r(   c                     UR                  U R                  5      nU(       aR  UR                  bE  U " 5       nUR                  UR                  UR                  UR
                  UR                  5        U$ SnU$ )zCreate a new instance of this class from the endpoint
object passed in.

@return: None or OpenIDServiceEndpoint for this endpoint objectN)
matchTypesopenid_type_urisrF   rH   rE   r   rG   )clsendpointr   openid_endpoints       r%   fromBasicServiceEndpoint.OpenIDServiceEndpoint.fromBasicServiceEndpoint   ss    
 ''(<(<=	 1!eO((););X\\)1););)1)A)AC  #Or(   c                 :   [         SS4[        SS4/n[        R                  " U5      n/ nU Hj  u  pgn[        R                  " UU5      n	U	c  M"  U " 5       n
Xl        [        R                  " UU5      U
l        Xl        U/U
l        UR                  U
5        Ml     U$ )zgParse the given document as HTML looking for an OpenID <link
rel=...>

@rtype: [OpenIDServiceEndpoint]
zopenid2.providerzopenid2.local_idzopenid.serverzopenid.delegate)
r   r   r   parseLinkAttrsfindFirstHrefr   r   r   r   append)rP   rF   htmldiscovery_types
link_attrsservicesr5   op_endpoint_rellocal_id_relop_endpoint_urlservices              r%   fromHTMLOpenIDServiceEndpoint.fromHTML   s     02DEo/@A

  ..t4
7F3H|(66z7FHO&eG!$)77
8D FG!0!)
GOOG$ 8G r(   c                     [        XU 5      $ )zParse the given document as XRDS looking for OpenID services.

@rtype: [OpenIDServiceEndpoint]

@raises XRDSError: When the XRDS does not parse.

@since: 2.1.0
)extractServices)rP   rF   xrdss      r%   fromXRDSOpenIDServiceEndpoint.fromXRDS   s     s#..r(   c                     UR                  5       (       a  U R                  nOU R                  nU" UR                  UR                  5      $ )zCreate endpoints from a DiscoveryResult.

@type discoveryResult: L{DiscoveryResult}

@rtype: list of L{OpenIDServiceEndpoint}

@raises XRDSError: When the XRDS does not parse.

@since: 2.1.0
)isXRDSrf   ra   normalized_uriresponse_text)rP   discoveryResultmethods      r%   fromDiscoveryResult)OpenIDServiceEndpoint.fromDiscoveryResult   sC     !!##\\F\\Fo44%335 	5r(   c                 8    U " 5       nXl         [        /Ul        U$ )zConstruct an OP-Identifier OpenIDServiceEndpoint object for
a given OP Endpoint URL

@param op_endpoint_url: The URL of the endpoint
@rtype: OpenIDServiceEndpoint
)r   r   r   )rP   r_   r`   s      r%   fromOPEndpointURL'OpenIDServiceEndpoint.fromOPEndpointURL   s!     %,01r(   c                     SU R                   R                  < SU R                   R                  < SU R                  < SU R                  < SU R
                  < SU R                  < SU R                  < S3$ )	N<.z server_url=z claimed_id=z
 local_id=z canonicalID=z used_yadis=z >)	__class__
__module____name__r   r   r   r    r!   r#   s    r%   __str__OpenIDServiceEndpoint.__str__   sI     ~~00$..2I2I'': 	;r(   )r    r   r"   r   r   r   r!   N)rx   rw   __qualname____firstlineno____doc__r   r   r   r   rO   r&   r,   r1   r6   r<   r?   r4   rH   rK   rS   classmethodra   rf   rn   rq   ry   __static_attributes__ r(   r%   r   r   +   s     		'/)I>B5( 
5&  ++CD< 8$H	/ 8$H5$ &&9:
 $$56	;r(   r   c                 n   / n[         U;   d
  [        U;   a  UR                  [        [        S5      5        [
        U;   a  UR                  [        [        S5      5        SnU HN  nU R                  U5       H6  nUc  UR                  nM  X5R                  :w  d  M%  SnXd4-  n[        US5      e   MP     U$ )a  Find the OP-Local Identifier for this xrd:Service element.

This considers openid:Delegate to be a synonym for xrd:LocalID if
both OpenID 1.X and OpenID 2.0 types are present. If only OpenID
1.X is present, it returns the value of openid:Delegate. If only
OpenID 2.0 is present, it returns the value of xrd:LocalID. If
there is more than one LocalID tag and the values are different,
it raises a DiscoveryFailure. This is also triggered when the
xrd:LocalID and openid:Delegate tags are different.

@param service_element: The xrd:Service element
@type service_element: ElementTree.Node

@param type_uris: The xrd:Type values present in this service
    element. This function could extract them, but higher level
    code needs to do that anyway.
@type type_uris: [str]

@raises DiscoveryFailure: when discovery fails.

@returns: The OP-Local Identifier for this service element, if one
    is present, or None otherwise.
@rtype: str or unicode or NoneType
DelegateLocalIDNz1More than one %r tag found in one service element)
r   r   rX   r   r   r   r   findalltextr   )rG   r   local_id_tagsr   local_id_taglocal_id_elementformatmessages           r%   rD   rD      s    8 M9$9(DU=*=>)#U:y9: H% / 7 7 E+00222L #33&w55 !F & Or(   c                      [         R                   " U 5      n[        R                  R                  U5      S   $ ! [         a  n[        SU< 3S5      eSnAff = f)zFNormalize a URL, converting normalization failures to
DiscoveryFailurer
   zNormalizing identifier: N)r   r9   r:   r;   
ValueErrorr   )url
normalizedwhys      r%   normalizeURLr   $  sU    5__S)
 ||%%j1!44  MsEtLLMs   : 
AAAc                 >    U R                   " S5      (       a  U SS n U $ )z1Normalize an XRI, stripping its scheme if presentzxri://   N)
startswithr   s    r%   normalizeXRIr   /  s!    
~~h!"gJr(   c                    ^^ S mUU4S jnT" U 5       VVs/ s H  u  p4U" U5      X44PM     nnnUR                  5         [        [        U5      5       H  nXV   S   XV'   M     U$ s  snnf )zvRearrange service_list in a new list so services are ordered by
types listed in preferred_types.  Return the new list.c                 b    [        [        [        [        [        U 5      5      5      U 5      5      $ )zfReturn an iterable that pairs the index of an element with
that element.

For Python 2.2 compatibility)listziprangelen)eltss    r%   	enumerate arrangeByType.<locals>.enumerate:  s$    
 CU3t9-.566r(   c                 j   > T" T5       H  u  pTU   U R                   ;   d  M  Us  $    [        T5      $ )aE  Return the index of the first matching type, or something
higher if no type matches.

This provides an ordering in which service elements that
contain a type that comes earlier in the preferred types list
come before service elements that come later. If a service
element has more than one type, the most preferred one wins.
)r   r   )r`   itr   preferred_typess      r%   bestMatchingService*arrangeByType.<locals>.bestMatchingServiceA  s;     o.DAq!W%6%66 / ?##r(      )sortr   r   )service_listr   r   
orig_indexsprio_servicesr   r   s    `     @r%   arrangeByTyper   6  s    7$$ -6l,CE,C* *!,j<,C  E 3}%&(+A. ' Es   A'c                 n    [        U [        /5      n[        U [        R                  5      n U=(       d    U $ )a  Extract OP Identifier services.  If none found, return the
rest, sorted with most preferred first according to
OpenIDServiceEndpoint.openid_type_uris.

openid_services is a list of OpenIDServiceEndpoint objects.

Returns a list of OpenIDServiceEndpoint objects.)r   r   r   rO   )openid_servicesop_servicess     r%   getOPOrUserServicesr   ^  s7      2E1FGK#O$9$J$JLO )/)r(   c                 *   [        U 5      nUR                  nUR                  n [        R	                  X#5      nU(       d5  UR                  5       (       a  [        U 5      $ [        R                  X#5      nU[        U5      4$ ! [
         a    / n NWf = f)a(  Discover OpenID services for a URI. Tries Yadis and falls back
on old-style <link rel='...'> discovery if Yadis fails.

@param uri: normalized identity URL
@type uri: str

@return: (claimed_id, services)
@rtype: (str, list(OpenIDServiceEndpoint))

@raises DiscoveryFailure: when discovery fails.
)
yadisDiscoverrj   rk   r   rf   r   ri   discoverNoYadisra   r   )rF   responserE   bodyr   s        r%   discoverYadisr   o  s      S!H''I!!D/88I
  ?? #3'' 088I*?;<<#  s   B BBc                    / n[        U 5      n  [        R                  " 5       R                  U [        R
                  5      u  p#Uc  [        SU < 35      e[        R                  " [        5      nU H#  nUR                  UR                  X5      5        M%     U H  nWUl        X&l        Xl        M     U [!        U5      4$ ! [         a    [        R                  SU -   5         NMf = f)NzNo CanonicalID found for XRI zxrds error on )r   r   ProxyResolverqueryr   rO   r   r   mkFilterextendgetServiceEndpointslogger	exceptionr    r   r"   r   )iname	endpointsr    r\   fltrG   rQ   s          r%   discoverXRIr     s    IE3 & 4 4 6 < <(99!; IJJ45'OS44ULM  (
   +)&+#  %i000  3)E123s   B
C "C'&C'c                     [         R                  " U 5      nUR                  S;  a  [        SUR                  < 3U5      eUR                  n[
        R                  UUR                  5      nX#4$ )N)      zCHTTP Response status from identity URL host is not 200. Got status )r   fetchstatusr   	final_urlr   ra   r   )rF   	http_respr   r   s       r%   r   r     sl    s#Iz)(//34=? 	? $$J+44Z5>^^EO&&r(   c                     [         R                  R                  U 5      nUS   (       a   US   (       a  US   S;  a  [        SS 5      eOSU -   n [	        U 5      n [        U 5      u  p#[	        U5      nX#4$ )Nr
      )httphttpszURI scheme is not HTTP or HTTPSzhttp://)r9   r:   urlparser   r   r   )rF   parsedr   r   s       r%   discoverURIr     sx    \\""3'FayVAY!9--"#DdKK . #o
s
C"/"4Jj)J&&r(   c                 b    [         R                  " U 5      S:X  a  [        U 5      $ [        U 5      $ )NXRI)r   identifierSchemer   r   )
identifiers    r%   r	   r	     s+    
J'50:&&:&&r(   )2r}   __all__urllib.parser9   loggingopenidr   r   r   openid.yadis.etxrdr   r   r   openid.yadis.servicesr   rd   openid.yadis.discoverr	   r   r   openid.yadisr   r   r   openid.consumerr   r   r   r   r   r   openid.messager   r0   r   r/   	getLoggerrx   r   objectr   rD   r   r   r   r   r   r   r   r   r   r(   r%   <module>r      s   	   $  ; ; @ ; 2 (  &-? ;00 > >			8	$D;F D;N/d5%P*"'=T16
'''r(   