
    qh                         S r / SQrSSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	J
r
  \	" 5       r\
" 5       rSSKJr   " S S	\5      r " S
 S\5      rS rSrSrS rS rS r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      r\" S5      rS rS r S'S jr!S r"\RF                   " S S\$5      5       r%\%" 5       r&S r'S  r(S! r)S" r*S# r+S$ r,S% r-S& r.g)(z+
ElementTree interface to an XRD document.
)nsTagmkXRDTagisXRDS	parseXRDSgetCanonicalIDgetYadisXRDgetPriorityStrictgetPriorityprioSortiterServicesexpandServiceexpandServices    N)datetime)strptime)importElementTreeimportSafeElementTree)xric                       \ rS rSrSrSrSrg)	XRDSError$   z An error with the XRDS document.N )__name__
__module____qualname____firstlineno____doc__reason__static_attributes__r       D/var/www/html/env/lib/python3.13/site-packages/openid/yadis/etxrd.pyr   r   $   s    * Fr   r   c                       \ rS rSrSrSrg)	XRDSFraud+   zZRaised when there's an assertion in the XRDS that it does not have
the authority to make.
r   N)r   r   r   r   r   r   r   r   r    r"   r"   +   s    r   r"   c                 `    [        U [        5      (       a  U R                  S5      OU n[        R	                  U5      n[
        R                  U5      n[        U5      (       d  [        S5      eU$ ! [        [        [        [        4 a    e [         a  n[        S5      nXEl        UeSnAff = f)zParse the given text as an XRDS document.

@return: ElementTree containing an XRDS document

@raises XRDSError: When there is a parse error or the document does
    not contain an XRDS.
utf8zNot an XRDS documentzError parsing document as XMLN)
isinstancestrencodeSafeElementTreeXMLElementTreer   r   
SystemExitMemoryErrorAssertionErrorImportError	Exceptionr   )text
bytestringelementtreewhyexcs         r    r   r   1   s     -7tS,A,AT[[(t
!%%j1 &&w/d||233 ^[A  78
	s   =A1 1$B-B((B-zxri://$xrd*($v*2.0)zxri://$xrdsc                     SU < SU< 3$ )N{}r   )nsts     r    r   r   S   s    1r   c                 "    [        [        U 5      $ )zmbasestring -> basestring

Create a tag name in the XRD 2.0 XML namespace suitable for using
with ElementTree
)r   
XRD_NS_2_0r;   s    r    r   r   W   s     Qr   c                 "    [        [        U 5      $ )zjbasestring -> basestring

Create a tag name in the XRDS XML namespace suitable for using
with ElementTree
)r   XRDS_NSr>   s    r    	mkXRDSTagrA   `   s     !r   XRDSServiceXRDTypeURIExpiresCanonicalIDc                 H    U R                  5       nUR                  [        :H  $ )z"Is this document an XRDS document?)getroottagroot_tag)xrd_treeroots     r    r   r   u   s    D88xr   c                 ^    SnU R                  [        5       H  nM     Uc  [        S5      eU$ )z=Return the XRD element that should contain the Yadis servicesNzNo XRD present in tree)findallxrd_tagr   rM   xrds     r    r   r   {   s9    
C ( )
 {011Jr   c                 |    U R                  [        5      nUc  U$ UR                  n[        US5      n[	        USS 6 $ )a~  Return the expiration date of this XRD element, or None if no
expiration was specified.

@type xrd_element: ElementTree node

@param default: The value to use as the expiration if no
    expiration was specified in the XRD.

@rtype: datetime.datetime

@raises ValueError: If the xrd:Expires element is present, but its
    contents are not formatted according to the specification.
z%Y-%m-%dT%H:%M:%SZr      )findexpires_tagr1   r   r   )xrd_elementdefaultexpires_elementexpires_stringexpires_times        r    getXRDExpirationr]      sK     "&&{3O(--  0DEa*++r   c                 l   UR                  [        5      nUR                  5          [        R                  " US   R                  [
        5      S   R                  5      nUR                  5       nUSS  Hh  nUR                  SS5      S   n[        R                  " UR                  [
        5      5      nXgR                  5       :w  a  [        U< SU< 35      eUnMj     [        R                  " U 5      n[        R                  " X5      (       d  [        U< SU< 35      eU$ ! [         a     gf = f)a  Return the CanonicalID from this XRDS document.

@param iname: the XRI being resolved.
@type iname: unicode

@param xrd_tree: The XRDS output from the resolver.
@type xrd_tree: ElementTree

@returns: The XRI CanonicalID or None.
@returntype: unicode or None
r   N   !z can not come from z can not come from root )rP   rQ   reverser   XRIcanonicalID_tagr1   
IndexErrorlowerrsplitfindtextr"   rootAuthorityproviderIsAuthoritative)	inamerM   xrd_listcanonicalIDchildIDrS   parent_soughtparentrN   s	            r    r   r      s    (Hgghqk11/B1EJJK !G|sA.q1o67LLN*&IJJ  U#D&&t55'4HII#  s   9D& &
D32D3c                   $    \ rS rSrSrS rS rSrg)_Max   z
Value that compares greater than any other value.

Should only be used as a singleton. Implemented for use as a
priority value for when a priority is not specified.
c                 ,    [        XR                  5      $ Nr&   	__class__selfothers     r    __lt___Max.__lt__       %00r   c                 ,    [        XR                  5      $ rt   ru   rw   s     r    __eq___Max.__eq__   r|   r   r   N)r   r   r   r   r   rz   r~   r   r   r   r    rq   rq      s    11r   rq   c                 r    U R                  S5      nUb  [        U5      nUS:  a  U$ [        S5      e[        $ )zGet the priority of this element.

Raises ValueError if the value of the priority is invalid. If no
priority is specified, it returns a value that compares greater
than any other value.
priorityr   z-Priority values must be non-negative integers)getint
ValueErrorMax)r3   prio_strprio_vals      r    r   r      s@     {{:&Hx=q=OLMM Jr   c                 F     [        U 5      $ ! [         a	    [        s $ f = f)zlGet the priority of this element

Returns Max if no priority is specified or the priority value is invalid.
)r   r   r   )r3   s    r    r	   r	      s&    
 )) 
s   
   c                 N    [         R                  " U 5        [        U [        S9nU$ )z5Sort a list of elements that have priority attributes)key)randomshufflesortedr	   )elementssorted_elemss     r    r
   r
      s"     NN8(4Lr   c                 T    [        U 5      n[        UR                  [        5      5      $ )zQReturn an iterable over the Service elements in the Yadis XRD

sorted by priority)r   r
   rP   service_tagrR   s     r    r   r     s"     h
CCKK,--r   c                 ~    [        U R                  [        5      5       Vs/ s H  nUR                  PM     sn$ s  snf )zYGiven a Service element, return a list of the contents of all
URI tags in priority order.)r
   rP   uri_tagr1   )service_elementuri_elements     r    
sortedURIsr     s?    
 $O$;$;G$DEEK 	E  s   :c                 j    U R                  [        5       Vs/ s H  oR                  PM     sn$ s  snf )zGGiven a Service element, return a list of the contents of all
Type tags)rP   type_tagr1   )r   type_elements     r    getTypeURIsr     s5     />.E.Eh.O.Ol.O  s   0c                     [        U 5      nU(       d  S/n/ nU H!  n[        U 5      nUR                  XCU 45        M#     U$ )z]Take a service element and expand it into an iterator of:
([type_uri], uri, service_element)
N)r   r   append)r   urisexpandeduri	type_uriss        r    r   r     sI     o&DvH0	9:  Or   c                 P    / nU  H  nUR                  [        U5      5        M     U$ )aq  Take a sorted iterator of service elements and expand it into a
sorted iterator of:
([type_uri], uri, service_element)

There may be more than one item in the resulting list for each
service element if there is more than one URI or type for a
service, but each triple will be unique.

If there is no URI or Type for a Service element, it will not
appear in the result.
)extendr   )service_elementsr   r   s      r    r   r   .  s+     H+o67 , Or   rt   )/r   __all__sysr   	functoolsr   timer   openid.oidutilr   r   r+   r)   openid.yadisr   r0   r   r"   r   r=   r@   r   r   rA   rL   r   rQ   r   r   rW   rc   r   r   r]   r   total_orderingobjectrq   r   r   r	   r
   r   r   r   r   r   r   r   r    <module>r      s        C!') 	 	 < #

  Vy!
5/F
5/y! =) ",2"J 16 1 1 f&. r   