
     h"                        d Z ddlmZmZmZmZ ddlmZ ddlZddl	Z	ddl
Z
ddlmZ ddlmZmZmZmZmZ e
j        dk     rdd	lmZmZ dd
lmZmZ nddlmZmZmZmZ ddZd Zd Z ej         de           ddZ!ddZ"dS )z
Functions to convert unicode IRIs into ASCII byte string URIs and back. Exports
the following items:

 - iri_to_uri()
 - uri_to_iri()
    )unicode_literalsdivisionabsolute_importprint_function)idnaN   )unwrap)byte_clsstr_cls	type_namebytes_to_list	int_types)   )urlsplit
urlunsplit)quoteunquote)r   unquote_to_bytesr   r   Fc                    t          | t                    s*t          t          dt	          |                               d}t
          j        dk     r|                     d          s|                     d          s~d}t          j	        d|           }|r/|
                    d          }d| t          |          d         z   } t          |           }|r$|| dd         z   } t          |dd	                   }nt          |           }|t          |j                  }|j        }||                    d
          }t          |j        d          }t          |j        d          }|j        }	|	"t          |	                              d          }	d}
||
|z  }
|r|
d|z   z  }
|
dz  }
||
|z  }
|	&|dk    o|	dk    }|dk    o|	dk    }|r|s
|s|
d|	z   z  }
t          |j        d          }t          |j        d          }t          |j        d          }|r|
||dk    rd}|d}t/          ||
|||f          }t          |t                    r|                    d          }|S )z
    Encodes a unicode IRI into an ASCII byte string URI

    :param value:
        A unicode string of an IRI

    :param normalize:
        A bool that controls URI normalization

    :return:
        A byte string of the ASCII-encoded URI
    z@
            value must be a unicode string, not %s
            N)      zhttp://zhttps://z	^[^:]*://r   r   r   z!$&'()*+,;=safeascii       :   @s   https   80s   httpss   443z/!$&'()*+,;=@:z/?!$&'()*+,;=@:   / latin1)
isinstancer   	TypeErrorr	   r   sysversion_info
startswithrematchgrouplenr   	_urlquoteschemehostnameencodeusernamepasswordportpathqueryfragmentr   )value	normalizer,   real_prefixprefix_matchparsedr-   r/   r0   r1   netlocdefault_httpdefault_httpsr2   r3   r4   outputs                    K/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/asn1crypto/_iri.py
iri_to_urir?   %   s    eW%%  e	
 
   	 F
&  )9)9))D)D UM]M]^hMiMi xU33 	9&,,Q//Kc+&6&6&7&7 88E% 	1%)+E{3B3/00F%~6=))H??6**~>>>H~>>>H;Dt}}##G,,F( 	&dXo%F$((:TU](*=tv~ 	" 	"m 	"dTk!F V['8999Dfl);<<<E/ABBBH U]x'7DDLL |uh?@@F&'"" )x((Mr   c                    t          | t                    s*t          t          dt	          |                               t          |           }|j        }||                    d          }t          |j	        ddg          }t          |j
        ddg          }|j        }|r|                    d          }|j        }|r*t          |t                    s|                    d          }d}|||z  }|r|d|z   z  }|dz  }|||z  }||dt          |          z   z  }t          |j        d	gd
          }t          |j        ddgd
          }	t          |j                  }
t%          ||||	|
f          S )z
    Converts an ASCII URI byte string into a unicode IRI

    :param value:
        An ASCII-encoded byte string of the URI

    :return:
        A unicode string of the IRI
    z=
            value must be a byte string, not %s
            Nr   :@)remapr   r    /T)rC   preserve&=)r"   r
   r#   r	   r   r   r,   decode_urlunquoter/   r0   r-   r1   r   r   r2   r3   r4   r   )r5   r9   r,   r/   r0   r-   r1   r:   r2   r3   r4   s              r>   
uri_to_irirJ   x   s    eX&&  e	
 
   	 e__F]Fw''6?3*===H6?3*===HH +??6**;D $JtY// ${{7##F( 	%cHn$F#(#%%v{3%$???DS#JFFFE6?++HvvtUH=>>>r   c                     t          | j        | j        | j                           }d |D             }d                    |          | j        fS )a>  
    Error handler for decoding UTF-8 parts of a URI into an IRI. Leaves byte
    sequences encoded in %XX format, but as part of a unicode string.

    :param exc:
        The UnicodeDecodeError exception

    :return:
        A 2-element tuple of (replacement unicode string, integer index to
        resume at)
    c                     g | ]}d |z  S )%%%02x ).0nums     r>   
<listcomp>z,_iri_utf8_errors_handler.<locals>.<listcomp>   s    <<<sHsN<<<r   r    )r   objectstartendjoin)excbytes_as_intsreplacementss      r>   _iri_utf8_errors_handlerrY      sM     "#*SYsw->"?@@M<<m<<<LGGL!!37++r   iriutf8r    c                    | | dk    rdS g t          j        d|           r6fd}t          j        d||           } fd}t          j        d||           } t          |                     d                              d                    }t          |t                    s|                    d	          }t                    d
k    rfd}t          j        d||          }|S )a  
    Quotes a unicode string for use in a URL

    :param string:
        A unicode string

    :param safe:
        A unicode string of character to not encode

    :return:
        None (if string is None) or an ASCII byte string of the quoted string
    Nr    z%[0-9a-fA-F]{2}c                     t          |                     d                    }|                    dd          }t                    D ](}|                    |dt          |          z            })|S )Nr   utf-8rZ   rM   )r   r)   rH   listreplaceord)r(   byte_stringunicode_string	safe_charr   s       r>   _try_unescapez _urlquote.<locals>._try_unescape   so    *5;;q>>::K(//CCN!$ZZ ^ ^	!/!7!7	8cR[nnC\!]!]!!r   z(?:%[0-9a-fA-F]{2})+c                 ~                         |                     d                              d                     dS )Nr   r    )appendr)   r.   )r(   escapess    r>   _extract_escapez"_urlquote.<locals>._extract_escape   s2    NN5;;q>>0099:::6r   r]   r   r   r   c                 .                         d          S )Nr   )pop)_rh   s    r>   _return_escapez!_urlquote.<locals>._return_escape   s    ;;q>>!r   s   %00)r'   searchsuburlquoter.   r"   r
   r*   )stringr   rd   ri   r=   rm   rh   s    `    @r>   r+   r+      s$    ~2t G	y"F++ D	" 	" 	" 	" 	" .vFF	 	 	 	 	 )?FCCfmmG,,4;;w3G3GHHHFfh'' (w'' 7||a	" 	" 	" 	" 	"77Mr   c                 8   | | S | dk    rdS |rag d}i }|D ]X}|                     d          }|||<   |                     |                    d          |                    d                    } Yt          |           } |rQ|D ]N}|                     |                    d          dt	          |          z                      d                    } O|                     dd	          }|r0|                                D ]\  }}|                    ||          }|S )
a  
    Unquotes a URI portion from a byte string into unicode using UTF-8

    :param byte_string:
        A byte string of the data to unquote

    :param remap:
        A list of characters (as unicode) that should be re-mapped to a
        %XX encoding. This is used when characters are not valid in part of a
        URL.

    :param preserve:
        A bool - indicates that the chars to be remapped if they occur in
        non-hex form, should be preserved. E.g. / for URL path.

    :return:
        A unicode string
    Nr   r    )r   r   rM   r]   rZ   )rk   r_   r.   r   r`   rH   items)	ra   rC   rE   rX   preserve_unmapcharreplacementr=   originals	            r>   rI   rI      sX   ( cr a??? 	a 	aD&**1--K*.N;'%--dkk'.B.BKDVDVW^D_D_``KK";//K l 	l 	lD%--dkk'.B.BXPSTXPYPYEYDaDabiDjDjkkKK33F ;%3%9%9%;%; 	; 	;!K^^K::FFMr   )F)r    )NN)#__doc__
__future__r   r   r   r   	encodingsr   codecsr'   r$   _errorsr	   _typesr
   r   r   r   r   r%   urlparser   r   urllibr   rp   r   r   urllib.parser?   rJ   rY   register_errorr+   rI   rN   r   r>   <module>r      s    S R R R R R R R R R R R        				 



       J J J J J J J J J J J J J Jd--------                   P P P Pf1? 1? 1?h, , ,$  i!9 : : :1 1 1 1h. . . . . .r   