B ”äî\ž3ã@sPdZddlZddlmZddlmZddlmZddlmZGdd „d eƒZ dS) z;Module containing the implementation of the URIMixin class.éNé)Ú exceptions)Úmisc)Ú normalizers)Ú validatorsc@sÄeZdZdZejZdd„Zdd„Zedd„ƒZ edd „ƒZ ed d „ƒZ d d „Z dd„Z d$dd„Zd%dd„Zd&dd„Zd'dd„Zd(dd„Zdd„Zd)dd„Zdd „Zejejejejejfd!d"„Zd#S)*ÚURIMixinz0Mixin with all shared methods for URIs and IRIs.cCsz|jsddddœS| ¡}|dkr6t |j |j¡¡‚| ¡}| d¡}|rvtj   |¡rvt   |¡svt |j |j¡¡‚|S)aÌReturn a dictionary with the ``userinfo``, ``host``, and ``port``. If the authority is not valid, it will raise a :class:`~rfc3986.exceptions.InvalidAuthority` Exception. :returns: ``{'userinfo': 'username:password', 'host': 'www.example.com', 'port': '80'}`` :rtype: dict :raises rfc3986.exceptions.InvalidAuthority: If the authority is not ``None`` and can not be parsed. N)ÚuserinfoÚhostÚportr ) Ú authorityÚ_match_subauthorityÚexcÚInvalidAuthorityÚencodeÚencodingÚ groupdictÚgetrZ IPv4_MATCHERÚmatchrZvalid_ipv4_host_address)ÚselfrÚmatchesr ©rúB/tmp/pip-build-uw_ogi45/urllib3/urllib3/packages/rfc3986/_mixin.pyÚauthority_infos    zURIMixin.authority_infocCstj |j¡S)N)rZSUBAUTHORITY_MATCHERrr )rrrrr 5szURIMixin._match_subauthoritycCs,y | ¡}Wntjk r"dSX|dS)z+If present, a string representing the host.Nr )rr r)rr rrrr 8s  z URIMixin.hostcCs,y | ¡}Wntjk r"dSX|dS)z2If present, the port extracted from the authority.Nr )rr r)rr rrrr As  z URIMixin.portcCs,y | ¡}Wntjk r"dSX|dS)z6If present, the userinfo extracted from the authority.Nr)rr r)rr rrrrJs  zURIMixin.userinfocCsttj | ¡¡ƒS)zéDetermine if this URI Reference is an absolute URI. See http://tools.ietf.org/html/rfc3986#section-4.3 for explanation. :returns: ``True`` if it is an absolute URI, ``False`` otherwise. :rtype: bool )ÚboolrZABSOLUTE_URI_MATCHERrÚunsplit)rrrrÚ is_absoluteSszURIMixin.is_absolutec Ksrt dt¡|j| dd¡f|j| dd¡f|j| dd¡f|j| dd¡f|j| dd¡fg}t dd „|DƒƒS) abDetermine if the URI is valid. .. deprecated:: 1.1.0 Use the :class:`~rfc3986.validators.Validator` object instead. :param bool require_scheme: Set to ``True`` if you wish to require the presence of the scheme component. :param bool require_authority: Set to ``True`` if you wish to require the presence of the authority component. :param bool require_path: Set to ``True`` if you wish to require the presence of the path component. :param bool require_query: Set to ``True`` if you wish to require the presence of the query component. :param bool require_fragment: Set to ``True`` if you wish to require the presence of the fragment component. :returns: ``True`` if the URI is valid. ``False`` otherwise. :rtype: bool zXPlease use rfc3986.validators.Validator instead. This method will be eventually removed.Zrequire_schemeFZrequire_authorityZ require_pathZ require_queryZrequire_fragmentcss|]\}}||ƒVqdS)Nr)Ú.0ÚvÚrrrrú {sz$URIMixin.is_valid..) ÚwarningsÚwarnÚDeprecationWarningÚscheme_is_validrÚauthority_is_validÚ path_is_validÚquery_is_validÚfragment_is_validÚall)rÚkwargsrrrrÚis_valid]szURIMixin.is_validFcCsDt dt¡y | ¡Wntjk r.dSXtj|j|j |dS)aDetermine if the authority component is valid. .. deprecated:: 1.1.0 Use the :class:`~rfc3986.validators.Validator` object instead. :param bool require: Set to ``True`` to require the presence of this component. :returns: ``True`` if the authority is valid. ``False`` otherwise. :rtype: bool zXPlease use rfc3986.validators.Validator instead. This method will be eventually removed.F)r Úrequire) r r!r"rr rrr$r r )rr+rrrr$}s zURIMixin.authority_is_validcCst dt¡t |j|¡S)a`Determine if the scheme component is valid. .. deprecated:: 1.1.0 Use the :class:`~rfc3986.validators.Validator` object instead. :param str require: Set to ``True`` to require the presence of this component. :returns: ``True`` if the scheme is valid. ``False`` otherwise. :rtype: bool zXPlease use rfc3986.validators.Validator instead. This method will be eventually removed.)r r!r"rr#Úscheme)rr+rrrr#™s zURIMixin.scheme_is_validcCst dt¡t |j|¡S)a\Determine if the path component is valid. .. deprecated:: 1.1.0 Use the :class:`~rfc3986.validators.Validator` object instead. :param str require: Set to ``True`` to require the presence of this component. :returns: ``True`` if the path is valid. ``False`` otherwise. :rtype: bool zXPlease use rfc3986.validators.Validator instead. This method will be eventually removed.)r r!r"rr%Úpath)rr+rrrr%ªs zURIMixin.path_is_validcCst dt¡t |j|¡S)a^Determine if the query component is valid. .. deprecated:: 1.1.0 Use the :class:`~rfc3986.validators.Validator` object instead. :param str require: Set to ``True`` to require the presence of this component. :returns: ``True`` if the query is valid. ``False`` otherwise. :rtype: bool zXPlease use rfc3986.validators.Validator instead. This method will be eventually removed.)r r!r"rr&Úquery)rr+rrrr&»s zURIMixin.query_is_validcCst dt¡t |j|¡S)aGDetermine if the fragment component is valid. .. deprecated:: 1.1.0 Use the Validator object instead. :param str require: Set to ``True`` to require the presence of this component. :returns: ``True`` if the fragment is valid. ``False`` otherwise. :rtype: bool zXPlease use rfc3986.validators.Validator instead. This method will be eventually removed.)r r!r"rr'Úfragment)rr+rrrr'Ìs zURIMixin.fragment_is_validcCst| ¡ƒt| ¡ƒkS)aCompare this URIReference to another URIReference. :param URIReference other_ref: (required), The reference with which we're comparing. :returns: ``True`` if the references are equal, ``False`` otherwise. :rtype: bool )ÚtupleÚ normalize)rZ other_refrrrÚnormalized_equalityÝszURIMixin.normalized_equalitycCst|tƒst|ƒ |¡}| ¡s*t |¡‚| ¡}|}|sR|j|jkrR|j dd}|jdk rr|j t   |j ¡d}n¦|j dk r–|j |jt   |j ¡d}n‚|j dkrÒ|jdk r²|j}n|j}|j |j|j |j |d}nF|j  d¡rìt   |j ¡}nt   t ||j ¡¡}|j |j|j ||jd}|S)a¢Use an absolute URI Reference to resolve this relative reference. Assuming this is a relative reference that you would like to resolve, use the provided base URI to resolve it. See http://tools.ietf.org/html/rfc3986#section-5 for more information. :param base_uri: Either a string or URIReference. It must be an absolute URI or it will raise an exception. :returns: A new URIReference which is the result of resolving this reference using ``base_uri``. :rtype: :class:`URIReference` :raises rfc3986.exceptions.ResolutionError: If the ``base_uri`` is not an absolute URI. N)r,)r-)r,r-)r,r r-r.ú/)Ú isinstancerÚtypeZ from_stringrr ÚResolutionErrorr1r,Ú copy_withrÚnormalize_pathr-r r.Ú startswithrZ merge_paths)rZbase_uriÚstrictZ resolvingÚtargetr.r-rrrÚ resolve_withçsD          zURIMixin.resolve_withcCs€g}|jr| |jdg¡|jr0| d|jg¡|jrB| |j¡|jdk r\| d|jg¡|jdk rv| d|jg¡d |¡S)z…Create a URI string from the components. :returns: The URI Reference reconstituted as a string. :rtype: str ú:z//Nú?ú#Ú)r,Úextendr r-Úappendr.r/Újoin)rZ result_listrrrr-s   zURIMixin.unsplitc CsR|||||dœ}x(t| ¡ƒD]\}}|tjkr||=qW|jf|Ž} |j| _| S)aCreate a copy of this reference with the new components. :param str scheme: (optional) The scheme to use for the new reference. :param str authority: (optional) The authority to use for the new reference. :param str path: (optional) The path to use for the new reference. :param str query: (optional) The query to use for the new reference. :param str fragment: (optional) The fragment to use for the new reference. :returns: New URIReference with provided components. :rtype: URIReference )r,r r-r.r/)ÚlistÚitemsrÚ UseExistingÚ_replacer) rr,r r-r.r/Ú attributesÚkeyÚvalueÚurirrrr7As   zURIMixin.copy_withN)F)F)F)F)F)F)Ú__name__Ú __module__Ú __qualname__Ú__doc__r0Ú__hash__rr Úpropertyr r rrr*r$r#r%r&r'r2r<rrrFr7rrrrr s(&        Fr) rOr r@rr rrrÚobjectrrrrrÚs