
    )Jf                         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dS )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                 V    |                      d          s| r| d         t          v rdS dS )zWDetermine if this identifier is an XRI or URI.

    @returns: C{"XRI"} or C{"URI"}
    xri://r   XRIURI)
startswithXRI_AUTHORITIES)
identifiers    S/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/yadis/xri.pyidentifierSchemer      s:    
 X&& : +5a=O+K+Kuu    c                 T    |                      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                     |                                  }|                    dd          }|                    dd          }|                    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"   %   sS     D<<U##D<<U##D<<U##DKr   c                 r    |                      dd          } t                              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          } |                     dd                                          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(   ;   sK     #u )#(((::g&::;;BBDDDr   c                 L    |                     d          }|d|         }|| k    S )zKIs this provider ID authoritative for this XRI?

    @returntype: bool
    r   N)rindex)
providerIDcanonicalIDlastbangparents       r   providerIsAuthoritativer;   C   s0     !!#&&H(#FZr   c                    |                      d          r
| dd         } |                     dd          d         }|d         dk    r!|d|                    d          dz            }nY|d         t          v r	|d         }nA|                    d	          }t	          t
          j        d
 |D                       }|d         }t          |          S )zReturn the root authority for an XRI.

    Example::

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

    @type xri: unicode
    @returntype: unicode
    r      Nr      r   r
   )r   c                 8    g | ]}|                     d           S )*)split).0ss     r   
<listcomp>z!rootAuthority.<locals>.<listcomp>h   s"    (H(H(H!(H(H(Hr   )r   rB   indexr   r   list__add__r   )r   	authorityrootsegmentss       r   rootAuthorityrL   N   s     ~~h !""g		#q!!!$I|s 2)//#..223	1	(	(| ??3''$,(H(Hx(H(H(HII{t99r   c                 :    |                      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;   rL   r    r   r   <module>rT      s    
 
			            000	 	 	   2:l##    & & &
E E E       @    r   