ó 9(Zc@`s>dZddlmZmZmZmZddlmZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZmZe jdkrÒdd lmZmZdd lmZmZn"dd lmZmZmZmZd „Zd „Zd„Zej deƒdd„Z!ddd„Z#dS(u‡ Functions to convert unicode IRIs into ASCII byte string URIs and back. Exports the following items: - iri_to_uri() - uri_to_iri() i(tunicode_literalstdivisiontabsolute_importtprint_function(tidnaNi(tunwrap(tbyte_clststr_clst type_namet bytes_to_listt int_typesi(turlsplitt urlunsplit(tquotetunquote(R tunquote_to_bytesR R cC`süt|tƒs-ttdt|ƒƒƒ‚nd}tjdkrÜ|jdƒ rÜ|jdƒ rÜd}t j d|ƒ}|r¦|j dƒ}d|t |ƒ}nt |ƒ}|rè||d}t|d ƒ}qèn t |ƒ}|dkrt|jƒ}n|j}|dk r-|jd ƒ}nt|jd d ƒ}t|jd d ƒ}|j}|dk r„t|ƒjd ƒ}nd } |dk rÄ| |7} |r·| d|7} n| d7} n|dk rÝ| |7} n|dk r;|dkoþ|dk} |dko|dk} | r;| r;| d|7} q;nt|jd dƒ} t|jd dƒ} t|jd dƒ}| dkr§|dkr§| dkr§d} n| dkr¼d} nt|| | | |fƒ}t|tƒrø|jdƒ}n|S(u¿ Normalizes and encodes a unicode IRI into an ASCII byte string URI :param value: A unicode string of an IRI :return: A byte string of the ASCII-encoded URI u@ value must be a unicode string, not %s iiuhttp://uhttps://u ^[^:]*://iiýÿÿÿuidnatsafeu !$&'()*+,;=uasciitt:t@thttpt80thttpst443u/!$&'()*+,;=@:u/?!$&'()*+,;=@:t/uulatin1N(ii(t isinstanceRt TypeErrorRRtNonetsyst version_infot startswithtretmatchtgrouptlenR t _urlquotetschemethostnametencodetusernametpasswordtporttpathtquerytfragmentR (tvalueR$t real_prefixt prefix_matchtparsedR%R'R(R)tnetloct default_httpt default_httpsR*R+R,toutput((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_iri.pyt iri_to_uri%sd /             $   c C`sËt|tƒs-ttdt|ƒƒƒ‚nt|ƒ}|j}|d k r`|jdƒ}nt |j dddgƒ}t |j dddgƒ}|j }|r·|jdƒ}n|j }|rèt|tƒ rè|jdƒ}nd}|d k r(||7}|r|d|7}n|d7}n|d k rA||7}n|d k rd|dt|ƒ7}nt |jddgd tƒ}t |jdd d gd tƒ} t |jƒ} t|||| | fƒS( u³ 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 u= value must be a byte string, not %s uasciitremapu:u@uidnauu/tpreserveu&u=N(RRRRRR R$Rtdecodet _urlunquoteR'R(R%R)R RR*tTrueR+R,R ( R-R0R$R'R(R%R)R1R*R+R,((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_iri.pyt uri_to_irius<            !cC`sOt|j|j|j!ƒ}g|D]}d|^q#}dj|ƒ|jfS(u> 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) u%%%02xu(R tobjecttstarttendtjoin(texct bytes_as_intstnumt replacements((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_iri.pyt_iri_utf8_errors_handler©s uiriutf8uc`s|d ks|dkrd Sg‰tjd|ƒr‡fd†}tjd||ƒ}‡fd†}tjd||ƒ}nt|jdƒdˆjdƒƒ}t|tƒsÄ|jdƒ}ntˆƒd krý‡fd †}tjd ||ƒ}n|S( u 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 uu%[0-9a-fA-F]{2}c`s^t|jdƒƒ}|jddƒ}x0tˆƒD]"}|j|dt|ƒƒ}q4W|S(Niuutf-8uiriutf8u%%%02x(RR!R8tlisttreplacetord(R t byte_stringtunicode_stringt safe_char(R(s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_iri.pyt _try_unescapeÖs  u(?:%[0-9a-fA-F]{2})+c`s#ˆj|jdƒjdƒƒdS(Niuasciiu(tappendR!R&(R (tescapes(s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_iri.pyt_extract_escapeàsuutf-8Ruasciiic`s ˆjdƒS(Ni(tpop(t_(RM(s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_iri.pyt_return_escapeëss%00N( RRtsearchtsubturlquoteR&RRR"(tstringRRKRNR4RQ((RMRs3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_iri.pyR#¾s$c C`s4|d kr|S|dkr dS|r’dddddg}i}xN|D]C}|jdƒ}|||<|j|jd ƒ|jd ƒƒ}qHWnt|ƒ}|ræx?|D]4}|j|jd ƒd t|ƒjd ƒƒ}q«Wn|jd d ƒ}|r0x/|jƒD]\}}|j||ƒ}q Wn|S(u 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 Ruuuuuuiuasciiu%%%02xuutf-8uiriutf8N(RRORFR&RRGR8titems( RHR6R7RCtpreserve_unmaptchart replacementR4toriginal((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_iri.pyR9òs(    +  5(i($t__doc__t __future__RRRRt encodingsRtcodecsRRt_errorsRt_typesRRRR R RturlparseR R turllibR RTRRt urllib.parseR5R;RDtregister_errorR#RR9(((s3/tmp/pip-build-wDUJoH/asn1crypto/asn1crypto/_iri.pyt s""   (" P 4  4