B \>9@sdZddlmZddlmZddlmZddlmZddlmZddlmZd Z d Z Gd d d e Z Gd ddede e Z Gdddede e ZddZddZdS)z3Module containing the urlparse compatibility logic.) namedtuple)compat) exceptions)misc) normalizers)uri) ParseResultParseResultBytes)schemeuserinfohostportpathqueryfragmentc@s@eZdZddZddZeddZeddZed d Zd S) ParseResultMixincsnfdddD\}}}|j|ks6|j|ks6|j|krh|rDd|}tt||jt||j|fS|j S)Nc3s|]}|VqdS)N).0p) attributesrG/tmp/pip-build-uw_ogi45/urllib3/urllib3/packages/rfc3986/parseresult.py "sz7ParseResultMixin._generate_authority..)r r rz{0}) r r rformatrZnormalize_authorityrto_strencoding authority)selfrr r rr)rr_generate_authoritys       z$ParseResultMixin._generate_authoritycCs|S)z*Shim to match the standard library method.)unsplit)rrrrgeturl0szParseResultMixin.geturlcCs|jS)z#Shim to match the standard library.)r )rrrrhostname4szParseResultMixin.hostnamecCs|jS)z#Shim to match the standard library.)r)rrrrnetloc9szParseResultMixin.netloccCs|jS)z#Shim to match the standard library.)r)rrrrparams>szParseResultMixin.paramsN) __name__ __module__ __qualname__rr propertyr!r"r#rrrrrs   rc seZdZdZdZdfdd ZedddZedd d Ze d d Z e j e j e j e j e j e j e j fddZ dddZdddZZS)r zImplementation of urlparse compatibility class. This uses the URIReference logic to handle compatibility with the urlparse.ParseResult class. rutf-8c s>tt|||pd|pd||p d|p&d||} | | _|| _| S)zCreate a new ParseResult.N)superr __new__r reference) clsr r r rrrruri_refr parse_result) __class__rrr*Ns zParseResult.__new__Nc Csd} |dk r| |d7} |dk r(| |7} |dk r>| d|7} tj|| ||||d} t| dd\}}}|| j|||| j| j| j| |d S) z-Create a ParseResult instance from its parts.N@z:{0})r rrrrrT)strict) r r r rrrrr-r) rr URIReference normalizeauthority_fromr rrr) r,r r r rrrrrrr-rrr from_parts^s.  zParseResult.from_partsTc CsLtj||}|s|}t||\}}}||j||||j|j|j||d S)aParse a URI from the given unicode URI string. :param str uri_string: Unicode URI to be parsed into a reference. :param str encoding: The encoding of the string provided :param bool strict: Parse strictly according to :rfc:`3986` if True. If False, parse similarly to the standard library's urlparse function. :returns: :class:`ParseResult` or subclass thereof ) r r r rrrrr-r) rr3 from_stringr4r5r rrr) r, uri_stringrr2lazy_normalizer+r r rrrrr7zs zParseResult.from_stringcCs|jjS)z Return the normalized authority.)r+r)rrrrrszParseResult.authorityc Cstt|||||||f}i} x,|D]$\} } | tjkr>t|| } | | | <q"W|| } |jj| d| | d| d| dd} tf| |j d| S)z>Create a copy of this instance replacing with specified parts.r rrr)r rrrr)r-r) zipPARSED_COMPONENTSr UseExistinggetattrrr+ copy_withr r)rr r r rrrrr attrs_dictnamevaluerrefrrrr>s      zParseResult.copy_withcs<p|jtttfdd|D}tf|jd|S)z+Convert to an instance of ParseResultBytes.c3s&|]}t|dr|n|VqdS)encodeN)hasattrrC)rattr)rrrrsz%ParseResult.encode..)r-r)rdictr:r;r r+)rrattrsr)rrrCs   zParseResult.encodeFcCs<|}|r2|jr2|jd}||j}|j|d}|jS)zCreate a URI string from the components. :returns: The parsed URI reconstituted as a string. :rtype: str idna)r )r rCdecoderr>r+r)ruse_idnar. hostbytesr rrrrs     zParseResult.unsplit)r()NNNNNNNr()r(TT)N)F)r$r%r&__doc__slotsr* classmethodr6r7r'rrr<r>rCr __classcell__rr)r/rr Ds     r c s|eZdZdZdfdd ZedddZedd d Zed d Z e j e j e j e j e j e j e j dfd dZ dddZ ZS)r zt|| } t| ts^t| dr^| |j } | | | <q"W| | } t j }|j j|| d|j || |j || d|j || d|j || d|j d}|s|}tf||j |d| S)z>Create a copy of this instance replacing with specified parts.rCr rrr)r rrrr)r-rr9)r:r;rr<r= isinstancebytesrDrCrrrrr+r>r4r )rr r r rrrrr9rr?r@rArrrBrrrr>!s0      zParseResultBytes.copy_withFcCsZ|}|r2|jr2|j|j}|d}|j|d}|jrD|jdd}|j}||jS)zCreate a URI bytes object from the components. :returns: The parsed URI reconstituted as a string. :rtype: bytes rH)r F)r9)r rIrrCr>r9r+r)rrJr.r rKrrrrrAs     zParseResultBytes.unsplit)rPT) NNNNNNNrPT)rPTT)F)r$r%r&rLr*rNr6r7r'rrr<r>rrOrr)r/rr s   r cCsd}}}d}|}d|kr,|dd\}}|drN|dd\}}|d7}d|krh|dd\}}n |st|rt|}|r|s|}|||fS)Nr1r[]:)rsplit startswithsplit)rr r rZ extra_hostrestrrrsplit_authorityTs  r\csy |Wn,tjk r8|r$t|j\}}}YnXfdddD\}}}|ry t|}Wntk rt|YnX|||fS)Nc3s|]}|VqdS)N)get)rr) subauthorityrrrysz!authority_from..)r r r)Zauthority_inforZInvalidAuthorityr\rrQ ValueErrorZ InvalidPort)r+r2r r rr)r^rr5os   r5N)rL collectionsrr0rrrrr__all__r;objectrr r r\r5rrrrs"      &