
    f                         d Z ddlZddlmZ ddlmZ g dZd Zd Z ej                  d      Z
d	 Zd
 Zd Zd Zd Zd Zd Zy)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                 B    | j                  d      s| r| d   t        v ryy)zWDetermine if this identifier is an XRI or URI.

    @returns: C{"XRI"} or C{"URI"}
    xri://r   XRIURI)
startswithXRI_AUTHORITIES)
identifiers    K/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/openid/yadis/xri.pyidentifierSchemer      s&    
 X&:+5a=O+K    c                 D    | j                  d      sd| z   } t        |       S )z$Transform an XRI to IRI-normal form.r   )r   escapeForIRIxris    r   toIRINormalr      s"    >>(#nr   z	\((.*?)\)c                     | j                         }|j                  dd      }|j                  dd      }|j                  dd      }|S )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                 ^    | j                  dd      } t        j                  t        |       } | S )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                 *    t        t        |             S )z$Transform an XRI to URI normal form.)iriToURIr   r   s    r   toURINormalr)   6   s    K$%%r   c                 ~    t        | t              rt        | d      } | j                  dd      j	                         S )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(   ;   s7     #u#(::g&::;BBDDr   c                 8    |j                  d      }|d| }|| k(  S )zKIs this provider ID authoritative for this XRI?

    @returntype: bool
    r   N)rindex)
providerIDcanonicalIDlastbangparents       r   providerIsAuthoritativer;   C   s+     !!#&H(#FZr   c           	         | j                  d      r| dd } | j                  dd      d   }|d   dk(  r"|d|j                  d      dz    }t        |      S |d   t        v r|d   }t        |      S |j                  d	      }t	        t
        j                  |D cg c]  }|j                  d
       c}      }|d   }t        |      S c c}w )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 t9 
1	(| t9	 ??3'$,,x(H!(HI{t9 )Is   C	
c                 2    | j                  d      sd| z   } | S )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      s[   
 
  0	 2::l#&
E @r   