o
    h                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ zdd	l	Z	W n e
y7   d	Z	Y nw G d
d dedejejZd	S )z?Module containing the implementation of the IRIReference class.    )
namedtuple   )compat)
exceptions)misc)normalizers)uriNc                       sP   e Zd ZdZdZ	d fdd	Zdd Zdd	 Zedd
dZ	dddZ
  ZS )IRIReferenceaA  Immutable object representing a parsed IRI Reference.

    Can be encoded into an URIReference object via the procedure
    specified in RFC 3987 Section 3.1

     .. note::
        The IRI submodule is a new interface and may possibly change in
        the future. Check for changes to the interface when upgrading.
     utf-8c                    s0   t t| | |p	d|pd|pd||}||_|S )zCreate a new IRIReference.N)superr	   __new__encoding)clsscheme	authoritypathqueryfragmentr   ref	__class__r
   S/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/rfc3986/iri.pyr   /   s   
zIRIReference.__new__c              	   C   sp   |}t |tr| j| }n#t |ts0z| j|}W n ty/   tdt| jt|jw t| t|kS )z"Compare this reference to another.z Unable to compare {0}() to {1}())	
isinstancetupler   r	   from_string	TypeErrorformattype__name__)selfotherZ	other_refr
   r
   r   __eq__>   s   

zIRIReference.__eq__c                 C   s   t j| jS N)r   ZISUBAUTHORITY_MATCHERmatchr   r    r
   r
   r   _match_subauthorityP   s   z IRIReference._match_subauthorityc              	   C   sZ   t ||}tj| }| |d |d t|d |t|d |t|d ||S )a	  Parse a IRI reference from the given unicode IRI string.

        :param str iri_string: Unicode IRI to be parsed into a reference.
        :param str encoding: The encoding of the string provided
        :returns: :class:`IRIReference` or subclass thereof
        r   r   r   r   r   )r   to_strr   ZIRI_MATCHERr$   	groupdictr   encode_component)r   Z
iri_stringr   Z	split_irir
   r
   r   r   S   s   zIRIReference.from_stringNc                    s   j }|rL du rtdu rtdfdd d}jr-d fddjdD }jdur>t	jj
d	 | }jdurL|d
tj 7 }tjj|jjjj
dS )a  Encode an IRIReference into a URIReference instance.

        If the ``idna`` module is installed or the ``rfc3986[idna]``
        extra is used then unicode characters in the IRI host
        component will be encoded with IDNA2008.

        :param idna_encoder:
            Function that encodes each part of the host component
            If not given will raise an exception if the IRI
            contains a host component.
        :rtype: uri.URIReference
        :returns: A URI reference
        NzICould not import the 'idna' module and the IRI hostname requires encodingc                    sJ   t dd | D r#ztj|  dddW S  tjy"   t jw | S )Nc                 s   s    | ]	}t |d kV  qdS )   N)ord).0cr
   r
   r   	<genexpr>   s    z<IRIReference.encode.<locals>.idna_encoder.<locals>.<genexpr>T)strict
std3_rules)anyidnaencodelower	IDNAErrorr   ZInvalidAuthorityr   )namer%   r
   r   idna_encoder~   s   
z)IRIReference.encode.<locals>.idna_encoder .c                    s   g | ]	}t  |qS r
   )r   r'   )r,   part)r7   r
   r   
<listcomp>   s    z'IRIReference.encode.<locals>.<listcomp>@:)r   r   r   r   )r   r2   r   ZMissingDependencyErrorhostjoinsplituserinfor   r)   r   portstrr   ZURIReferencer   r   r   r   )r    r7   r   r
   )r7   r    r   r3   g   s@   




zIRIReference.encode)r   r#   )r   
__module____qualname____doc__slotsr   r"   r&   classmethodr   r3   __classcell__r
   r
   r   r   r	       s    
r	   )rF   collectionsr   r8   r   r   r   r   r   r2   ImportErrorZURI_COMPONENTSZURIMixinr	   r
   r
   r
   r   <module>   s    
