
    )Jf                         d Z g dZddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
  e	            Z e
            ZddlmZ  G d d	e          Z G d
 de          Zd ZdZdZd Zd Zd Z ed          Z ed          Z ed          Z ed          Z ed          Z ed          Z ed          Zd Zd Z d'dZ!d Z"ej#         G d de$                      Z% e%            Z&d Z'd  Z(d! Z)d" Z*d# Z+d$ Z,d% Z-d& Z.dS )(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                       e Zd ZdZdZdS )	XRDSErrorz An error with the XRDS document.N)__name__
__module____qualname____doc__reason     U/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/yadis/etxrd.pyr   r   $   s        ** FFFr   r   c                       e Zd ZdZdS )	XRDSFraudzbRaised when there's an assertion in the XRDS that it does not have
    the authority to make.
    N)r   r   r   r   r   r   r   r   r   +   s           r   r   c                    	 t          | t                    r|                     d          n| }t                              |          }t
                              |          }t          |          st          d          |S # t          t          t          t          f$ r  t          $ r}t          d          }||_        |d}~ww xY w)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,AKT[[(((t
!%%j11 &&w//d|| 	42333 ^[A      788
	s   AB 'C)CCzxri://$xrd*($v*2.0)zxri://$xrdsc                     d| d|S )N{}r   )nsts     r   r   r   S   s     rr11r   c                 ,    t          t          |           S )zybasestring -> basestring

    Create a tag name in the XRD 2.0 XML namespace suitable for using
    with ElementTree
    )r   
XRD_NS_2_0r7   s    r   r   r   W   s     Qr   c                 ,    t          t          |           S )zvbasestring -> basestring

    Create a tag name in the XRDS XML namespace suitable for using
    with ElementTree
    )r   XRDS_NSr:   s    r   	mkXRDSTagr=   `   s     !r   XRDSServiceXRDTypeURIExpiresCanonicalIDc                 J    |                                  }|j        t          k    S )z"Is this document an XRDS document?)getroottagroot_tag)xrd_treeroots     r   r   r   u   s     D8xr   c                 f    d}|                      t                    D ]}|t          d          |S )z=Return the XRD element that should contain the Yadis servicesNzNo XRD present in tree)findallxrd_tagr   rI   xrds     r   r   r   {   sD    
C ((   {0111Jr   c                     |                      t                    }||S |j        }t          |d          }t	          |dd          S )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.
    Nz%Y-%m-%dT%H:%M:%SZr      )findexpires_tagr-   r   r   )xrd_elementdefaultexpires_elementexpires_stringexpires_times        r   getXRDExpirationrY      sP     "&&{33O(-  0DEEac*++r   c                    |                     t                    }|                                 	 t          j        |d                              t
                    d         j                  }n# t          $ r Y dS w xY w|                                }|dd         D ]x}|	                    dd          d         }t          j        |
                    t
                              }||                                k    rt          |d|          |}yt          j        |           }t          j        ||          st          |d|          |S )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 )rL   rM   reverser   XRIcanonicalID_tagr-   
IndexErrorlowerrsplitfindtextr   rootAuthorityproviderIsAuthoritative)	inamerI   xrd_listcanonicalIDchildIDrO   parent_soughtparentrJ   s	            r   r   r      sP    ((Hghqk11/BB1EJKK   tt !!G|    sA..q1o6677FLLNN**&&IJJJU##D&tW55 J'''44HIIIs   =A. .
A<;A<c                       e Zd ZdZd Zd ZdS )_Maxz
    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                 ,    t          || j                  S Nr"   	__class__selfothers     r   __lt__z_Max.__lt__       %000r   c                 ,    t          || j                  S ro   rp   rr   s     r   __eq__z_Max.__eq__   rv   r   N)r   r   r   r   ru   rx   r   r   r   rm   rm      s<         1 1 11 1 1 1 1r   rm   c                     |                      d          }|&t          |          }|dk    r|S t          d          t          S )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.
    priorityNr   z-Priority values must be non-negative integers)getint
ValueErrorMax)r/   prio_strprio_vals      r   r   r      sJ     {{:&&Hx==q==OLMMM Jr   c                 P    	 t          |           S # t          $ r
 t          cY S w xY w)ztGet the priority of this element

    Returns Max if no priority is specified or the priority value is invalid.
    )r   r}   r~   )r/   s    r   r	   r	      s9    
 )))   


s    %%c                 Z    t          j        |            t          | t                    }|S )z5Sort a list of elements that have priority attributes)key)randomshufflesortedr	   )elementssorted_elemss     r   r
   r
      s,     N8(444Lr   c                 n    t          |           }t          |                    t                              S )zUReturn an iterable over the Service elements in the Yadis XRD

    sorted by priority)r   r
   rL   service_tagrN   s     r   r   r     s+     h

CCKK,,---r   c                 d    d t          |                     t                              D             S )z]Given a Service element, return a list of the contents of all
    URI tags in priority order.c                     g | ]	}|j         
S r   r-   ).0uri_elements     r   
<listcomp>zsortedURIs.<locals>.<listcomp>  s+        	  r   )r
   rL   uri_tagservice_elements    r   
sortedURIsr     s9     #O$;$;G$D$DEE   r   c                 J    d |                      t                    D             S )zKGiven a Service element, return a list of the contents of all
    Type tagsc                     g | ]	}|j         
S r   r   )r   type_elements     r   r   zgetTypeURIs.<locals>.<listcomp>  s(       *  r   )rL   type_tagr   s    r   getTypeURIsr     s1     .=.E.Eh.O.O   r   c                     t          |           }|sdg}g }|D ])}t          |           }|                    ||| f           *|S )zeTake 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     sb     o&&D vH ; ;00	C9::::Or   c                 X    g }| D ]$}|                     t          |                     %|S )a  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+ 8 8o667777Or   ro   )/r   __all__sysr   	functoolsr   timer   openid.oidutilr   r   r'   r%   openid.yadisr   r,   r   r   r   r9   r<   r   r   r=   rH   r   rM   r   r   rS   r_   r   r   rY   r   total_orderingobjectrm   r~   r   r	   r
   r   r   r   r   r   r   r   r   <module>r      s      


                  C C C C C C C C!!''))          	       	     < #

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