
    qh                         S r SSKrSSKJr  SSKJr  / SQrS rS r\R                  " S5      r
S	 rS
 rS rS rS rS rS rg)zUtility functions for handling XRIs.

@see: XRI Syntax v2.0 at the U{OASIS XRI Technical Committee<http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=xri>}
    N)reduce)	codecutil)!=@+$(c                 Z    U R                  S5      (       d  U (       a  U S   [        ;   a  gg)zODetermine if this identifier is an XRI or URI.

@returns: C{"XRI"} or C{"URI"}
xri://r   XRIURI)
startswithXRI_AUTHORITIES)
identifiers    B/var/www/html/env/lib/python3.13/site-packages/openid/yadis/xri.pyidentifierSchemer      s)    
 X&&:+5a=O+K    c                 N    U R                  S5      (       d  SU -   n [        U 5      $ )z$Transform an XRI to IRI-normal form.r   )r   escapeForIRIxris    r   toIRINormalr      s%    >>(##nr   z	\((.*?)\)c                     U R                  5       nUR                  SS5      nUR                  SS5      nUR                  SS5      nU$ )zKEscape things that need to be escaped if they're in a cross-reference.
    /z%2F?z%3F#z%23)groupreplace)
xref_matchxrefs     r   _escape_xrefr"   %   sG     D<<U#D<<U#D<<U#DKr   c                 ^    U R                  SS5      n [        R                  [        U 5      n U $ )zBEscape things that need to be escaped when transforming to an IRI.%z%25)r   _xref_resubr"   r   s    r   r   r   /   s'    
++c5
!C
,,|S
)CJr   c                 *    [        [        U 5      5      $ )z$Transform an XRI to URI normal form.)iriToURIr   r   s    r   toURINormalr)   6   s    K$%%r   c                 |    [        U [        5      (       a
  [        U SS9n U R                  SSS9R	                  5       $ )z.Transform an IRI to a URI by escaping unicode.zutf-8)encodingasciioid_percent_escape)errors)
isinstancebytesstrencodedecode)iris    r   r(   r(   ;   s:     #u#(::g&::;BBDDr   c                 6    UR                  S5      nUSU nX0:H  $ )zCIs this provider ID authoritative for this XRI?

@returntype: bool
r   N)rindex)
providerIDcanonicalIDlastbangparents       r   providerIsAuthoritativer;   C   s)     !!#&H(#Fr   c           	         U R                  S5      (       a  U SS n U R                  SS5      S   nUS   S:X  a  USUR                  S5      S-    nObUS   [        ;   a  US   nOOUR                  S	5      n[	        [
        R                  U Vs/ s H  oDR                  S
5      PM     sn5      nUS   n[        U5      $ s  snf )zReturn the root authority for an XRI.

Example::

    rootAuthority("xri://@example") == "xri://@"

@type xri: unicode
@returntype: unicode
r      Nr      r   r
   )r   *)r   splitindexr   r   list__add__r   )r   	authorityrootsegmentsss        r   rootAuthorityrI   N   s     ~~h!"g		#q!!$I|s 2)//#.23	1	(| ??3'$,,x(Hx!x(HI{t9 )Is   B?
c                 <    U R                  S5      (       d  SU -   n U $ )a  An XRI object allowing comparison of XRI.

Ideally, this would do full normalization and provide comparsion
operators as per XRI Syntax.  Right now, it just does a bit of
canonicalization by ensuring the xri scheme is present.

@param xri: an xri string
@type xri: unicode
r   )r   r   s    r   r   r   n   s!     >>(##nJr   )__doc__re	functoolsr   openidr   r   r   r   compiler%   r"   r   r)   r(   r;   rI   r    r   r   <module>rQ      sY   
 
  0	 ::l#&
E @r   