ó ½z]c@s¨dZddlZddlmZddlmZd„Zd„Zd„Zd „Zd „Z d „Z d „Z d „Z ej dƒZd„Zd„Zd„ZdS(s.Module with functions to normalize components.iÿÿÿÿNi(tcompat(tmisccCs |jƒS(sNormalize the scheme component.(tlower(tscheme((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pytnormalize_schemescCsf|\}}}d}|r2|t|ƒd7}n|rK|t|ƒ7}n|rb|d|7}n|S(s)Normalize an authority tuple to a string.tt@t:(tnormalize_percent_characterstnormalize_host(t authoritytuserinfothosttporttresult((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pytnormalize_authorityscCs tj|ƒS(s<Normalize a username to make it safe to include in userinfo.(Rturlquote(tusername((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pytnormalize_username(scCs tj|ƒS(s/Normalize a password to make safe for userinfo.(RR(tpassword((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pytnormalize_password-scCs±tjj|ƒr§|jdƒ}|dkr§|jdƒ}|dksv||ksv||krŽ|t|ƒdkrŽ|jdddƒ}n|| jƒ||Sn|jƒS(sNormalize a host string.t%iÿÿÿÿs%25ii(Rt IPv6_MATCHERtmatchtfindtlentreplaceR(R tpercentt percent_25((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pyR 2s "cCs |s |St|ƒ}t|ƒS(sNormalize the path string.(Rtremove_dot_segments(tpath((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pytnormalize_pathFs cCs|s |St|ƒS(sNormalize the query string.(R(tquery((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pytnormalize_queryOscCs|s |St|ƒS(sNormalize the fragment string.(R(tfragment((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pytnormalize_fragmentVss%[A-Fa-f0-9]{2}cCsQttj|ƒƒ}x5|D]-}|jƒs|j||jƒƒ}qqW|S(sAll percent characters should be upper-cased. For example, ``"%3afoo%DF%ab"`` should be turned into ``"%3Afoo%DF%AB"``. (tsettPERCENT_MATCHERtfindalltisupperRtupper(tstmatchestm((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pyR`s   cCsÆ|jdƒ}g}xO|D]G}|dkr4qq|dkrP|j|ƒq|r|jƒqqW|jdƒrš| s‡|drš|jddƒn|jdƒr¹|jdƒndj|ƒS( sURemove dot segments from the string. See also Section 5.2.4 of :rfc:`3986`. t/t.s..iRs/.s/..(s/.s/..(tsplittappendtpopt startswithtinserttendswithtjoin(R)tsegmentstoutputtsegment((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pyRls    c Cs|dkr|Sttjtj||ƒƒƒ}tj||ƒ}||jdƒk}tƒ}x¢t dt|ƒƒD]‹}|||d!}t |ƒ}|r¬|dksÍ|dkrà|j ƒt j krà|j|ƒqwn|jdj|ƒjƒjƒƒqwW|j |ƒS(s7Encode the specific component in the provided encoding.Riii€s%{0:02x}N(tNoneRR%R&Rtto_strtto_bytestcountt bytearraytrangetordtdecodeRtNON_PCT_ENCODEDtextendtformattencodeR(( t uri_componenttencodingtpercent_encodingst uri_bytestis_percent_encodedt encoded_urititbytetbyte_ord((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pytencode_componentŽs     ! &(t__doc__treRRRRRRRR RR!R#tcompileR%RRRM(((sE/tmp/pip-build-kBFYxq/urllib3/urllib3/packages/rfc3986/normalizers.pyts        "