a
    xd                     @   s   d Z ddlZddlmZ ddlmZ g dZdd Zdd	 Ze	d
Z
dd Zdd Zdd Zdd Zdd Zdd Zd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                 C   s&   |  ds| r| d tv rdS dS dS )zWDetermine if this identifier is an XRI or URI.

    @returns: C{"XRI"} or C{"URI"}
    xri://r   XRIURIN)
startswithXRI_AUTHORITIES)
identifier r   H/var/www/html/Ranjet/env/lib/python3.9/site-packages/openid/yadis/xri.pyidentifierScheme   s
    
r   c                 C   s   |  dsd|  } t| S )z$Transform an XRI to IRI-normal form.r
   )r   escapeForIRIxrir   r   r   toIRINormal   s    
r   z	\((.*?)\)c                 C   s0   |   }|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)Z
xref_matchZxrefr   r   r   _escape_xref%   s
    r   c                 C   s   |  dd} tt| } | S )zBEscape things that need to be escaped when transforming to an IRI.%z%25)r   _xref_resubr   r   r   r   r   r   /   s    r   c                 C   s   t t| S )z$Transform an XRI to URI normal form.)iriToURIr   r   r   r   r   toURINormal6   s    r!   c                 C   s(   t | trt| dd} | jddd S )z.Transform an IRI to a URI by escaping unicode.zutf-8)encodingasciiZoid_percent_escape)errors)
isinstancebytesstrencodedecode)Zirir   r   r   r    ;   s    
r    c                 C   s   | d}|d| }|| kS )zKIs this provider ID authoritative for this XRI?

    @returntype: bool
    r   N)rindex)Z
providerIDZcanonicalIDZlastbangparentr   r   r   providerIsAuthoritativeC   s    
r,   c                 C   s   |  dr| dd } | ddd }|d dkrJ|d|dd  }n>|d tv r`|d }n(|d	}ttjd
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                 S   s   g | ]}| d qS )*)split).0sr   r   r   
<listcomp>h       z!rootAuthority.<locals>.<listcomp>)r   r1   indexr   r   list__add__r   )r   	authorityrootsegmentsr   r   r   rootAuthorityN   s    



r<   c                 C   s   |  dsd|  } | 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   r   r   r   r   n   s    

r   )__doc__re	functoolsr   Zopenidr   r   r   r   compiler   r   r   r!   r    r,   r<   r   r   r   r   r   <module>   s   

 