
    f                         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jF                   G d de$             Z% e%       Z&d Z'd  Z(d! Z)d" Z*d# Z+d$ Z,d% Z-d& Z.y)(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y)	XRDSErrorz An error with the XRDS document.N)__name__
__module____qualname____doc__reason     M/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/openid/yadis/etxrd.pyr   r   $   s    * Fr   r   c                       e Zd ZdZy)	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                 J   	 t        | t              r| j                  d      n| }t        j	                  |      }t
        j                  |      }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,AT[[(t
!%%j1 &&w/d|233 ^[A  78
	s   8A' '"B"	BB"zxri://$xrd*($v*2.0)zxri://$xrdsc                     d| d|S )N{}r   )nsts     r   r   r   S   s    1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                 H    | 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88xr   c                 X    d}| j                  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   {   s>    
C ( 
 {011Jr   c                 z    | j                  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.
    z%Y-%m-%dT%H:%M:%SZr      )findexpires_tagr-   r   r   )xrd_elementdefaultexpires_elementexpires_stringexpires_times        r   getXRDExpirationrY      sK     "&&{3O(--  0DEa*++r   c                 N   |j                  t              }|j                          	 t        j                  |d   j                  t
              d   j                        }|j                         }|dd D ]d  }|j                  dd      d   }t        j                  |j                  t
                    }||j                         k7  rt        |d|      |}f t        j                  |       }t        j                  ||      st        |d|      |S # t        $ r Y yw xY w)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      s    (Hgghqk11/B1EJJK !G|  sA.q1o67FLLN*&IJJ  U#D&&tW5'4HII#  s   8D 	D$#D$c                       e Zd ZdZd Zd Zy)_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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1r   rm   c                 n    | j                  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.
    priorityr   z-Priority values must be non-negative integers)getint
ValueErrorMax)r/   prio_strprio_vals      r   r   r      s@     {{:&Hx=q=OLMM Jr   c                 D    	 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	      s&    
 )) 
s   
 c                 R    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"     NN8(4Lr   c                 T    t        |       }t        |j                  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                 x    t        | j                  t                    D cg c]  }|j                   c}S c c}w )z]Given a Service element, return a list of the contents of all
    URI tags in priority order.)r
   rL   uri_tagr-   )service_elementuri_elements     r   
sortedURIsr     s:    
 $O$;$;G$DE 	  s   7c                 f    | j                  t              D cg c]  }|j                   c}S c c}w )zKGiven a Service element, return a list of the contents of all
    Type tags)rL   type_tagr-   )r   type_elements     r   getTypeURIsr     s2     />.E.Eh.O*  s   .c                 v    t        |       }|sdg}g }|D ]!  }t        |       }|j                  ||| 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     sP     o&DvH ;0	C9:; Or   c                 L    g }| D ]  }|j                  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   .  s0     H+ 8o678 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!') 	 	 < #

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