ó ½z]c@@sBddlmZddlZddlmZddlmZddlmZm Z ddl m Z m Z ddl mZdd lmZmZmZmZd d d d dddgZdZejdƒZejejBdddhBZedhBZZdedeƒfd„ƒYZd„Zdd„Z d„Z!d„Z"dS( i(tabsolute_importN(t namedtuplei(tLocationParseError(tsixtrfc3986(tRFC3986ExceptiontValidationError(t Validator(t abnf_regexpt normalizerstcompattmisctschemetauththosttporttpathtquerytfragmentthttpthttpss^(?:[a-zA-Z][a-zA-Z0-9+\-]*:|/)t:t@t/t?tUrlcB@sweZdZdZdddddddd„Zed„ƒZed„ƒZed„ƒZ ed„ƒZ d„Z RS( sÍ Data structure for representing an HTTP URL. Used as a return value for :func:`parse_url`. Both the scheme and host are normalized as they are both case-insensitive according to RFC 3986. c C@si|r#|jdƒ r#d|}n|dk r>|jƒ}ntt|ƒj||||||||ƒS(NR(t startswithtNonetlowertsuperRt__new__(tclsR R RRRRR((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyR!s   !cC@s|jS(s@For backwards-compatibility with urlparse. We're nice like that.(R(tself((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pythostname*scC@s6|jp d}|jdk r2|d|j7}n|S(s)Absolute path including the query string.RRN(RRR(R turi((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyt request_uri/scC@s$|jrd|j|jfS|jS(s(Network location including host and ports%s:%d(RR(R ((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pytnetloc9s c C@sî|\}}}}}}}d}|dk r>||d7}n|dk r[||d7}n|dk rt||7}n|dk r—|dt|ƒ7}n|dk r°||7}n|dk rÍ|d|7}n|dk rê|d|7}n|S(sˆ Convert self into a url This function should more or less round-trip with :func:`.parse_url`. The returned url may not be exactly the same as the url inputted to :func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls with a blank port will have : removed). Example: :: >>> U = parse_url('http://google.com/mail/') >>> U.url 'http://google.com/mail/' >>> Url('http', 'username:password', 'host.com', 80, ... '/path', 'query', 'fragment').url 'http://username:password@host.com:80/path?query#fragment' uu://u@u:u?u#N(Rtstr( R R R RRRRRturl((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyR&@s"         cC@s|jS(N(R&(R ((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyt__str__hs(N( t__name__t __module__t__doc__t __slots__RRtpropertyR!R#R$R&R'(((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyRs (cC@s£d}d}xV|D]N}|j|ƒ}|dkr:qn|dksR||kr|}|}qqW|dks}|dkrŠ|ddfS|| ||d|fS(sì .. deprecated:: 1.25 Given a string and an iterable of delimiters, split on the first found delimiter. Return two split parts and the matched delimiter. If not found, then the first part is the full input string. Example:: >>> split_first('foo/bar?baz', '?/=') ('foo', 'bar?baz', '/') >>> split_first('foo/bar?baz', '123') ('foo/bar?baz', '', None) Scales linearly with number of delims. Not ideal for large number of delims. itiN(Rtfind(tstdelimstmin_idxt min_delimtdtidx((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyt split_firstls    sutf-8c C@s|dkr|Sttjjtj||ƒƒƒ}|jddƒ}||jdƒk}t ƒ}xŸt dt|ƒƒD]ˆ}|||d!}t |ƒ} |r¯|dksÍ| dkrà|j ƒ|krà|j |ƒqzn|j dj| ƒjƒjƒƒqzW|j |ƒS( sšPercent-encodes a URI component without reapplying onto an already percent-encoded component. Based on rfc3986.normalizers.encode_component() sutf-8t surrogatepasst%iii€s%{0:02x}N(RtlenR tPERCENT_MATCHERtfindallR tto_strtencodetcountt bytearraytrangetordtdecodetextendtformattupper( t componentt allowed_charstencodingtpercent_encodingst uri_bytestis_percent_encodedtencoded_componenttitbytetbyte_ord((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyt_encode_invalid_charss      &c @sv|s tƒSt|tjƒ ‰tj|ƒs<d|}nd„}ytjjt j |ƒƒj ƒ}t j |d|dt|dtƒt|dtƒt|dtƒƒ}|jdk }|jd|ƒ}Wn*ttfk rtjt|ƒdƒSX|r&|jdkr&t|ƒ‚n|jdksJ|jjƒtkrY|jƒ}ntƒ}y|j|jŒj |ƒWn$t!k r¥tjt|ƒdƒSX|j"}|så|j#dk sÓ|j$dk rÜd }qåd}n‡fd †}td||jƒd ||j%ƒd ||j&ƒd |j'dk rEt(|j'ƒndd||ƒd||j#ƒd||j$ƒƒS(s¤ Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is performed to parse incomplete urls. Fields not provided will be None. This parser is RFC 3986 compliant. :param str url: URL to parse into a :class:`.Url` namedtuple. Partly backwards-compatible with :mod:`urlparse`. Example:: >>> parse_url('http://google.com/mail/') Url(scheme='http', host='google.com', port=None, path='/mail/', ...) >>> parse_url('google.com:80') Url(scheme=None, host='google.com', port=80, path=None, ...) >>> parse_url('/foo?bar') Url(scheme=None, host=None, port=None, path='/foo', query='bar', ...) s//cS@s²|r®tg|D]}t|ƒdk^qƒr®yddl}Wntk r`tdƒ‚nXy#|j|jƒdtdtƒSWq®|jk rªtd|ƒ‚q®Xn|S(Ni€is-Unable to parse URL without the 'idna' moduletstrictt std3_rulesu#Name '%s' is not a valid IDNA label( tanyR@tidnat ImportErrorRR<RtTruet IDNAError(tnametxRS((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyt idna_encodeÏs1 #R t authorityRRRt idna_encoderR-c@s;|dkrdSˆ r7t|tjƒ r7|jdƒS|S(Nsutf-8(Rt isinstanceRt binary_typeR<(RX(t is_string(s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyt to_input_type s   R RRN()RR\RR]t SCHEME_REGEXtsearchR t IRI_MATCHERtmatchR R;t groupdictRt IRIReferenceROt PATH_CHARSt QUERY_CHARStFRAGMENT_CHARSRZRR<t ValueErrorRt raise_fromRR RtNORMALIZABLE_SCHEMESt normalizeRtcheck_validity_oftCOMPONENT_NAMEStvalidateRRRRtuserinfoRRtint( R&RYt split_iritiri_reft has_authorityturi_reft validatorRR_((R^s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyt parse_url®sV  !$       $ cC@s(t|ƒ}|jpd|j|jfS(s4 Deprecated. Use :func:`parse_url` instead. R(RwR R!R(R&tp((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pytget_hosts (RRN(#t __future__Rtret collectionsRt exceptionsRtpackagesRRtpackages.rfc3986.exceptionsRRtpackages.rfc3986.validatorsRtpackages.rfc3986RR R R t url_attrsRRktcompileR`tUNRESERVED_CHARS_SETtSUB_DELIMITERS_SETRfRgRhRR5RORwRy(((s1/tmp/pip-build-kBFYxq/urllib3/urllib3/util/url.pyts" "S #  n