3 ]3@sPdZddlZddlmZddlmZddlmZddlmZGdd d eZ dS) z;Module containing the implementation of the URIMixin class.N) exceptions)misc) normalizers) validatorsc@seZdZdZejZddZddZeddZ edd Z ed d Z d d Z ddZ d$ddZd%ddZd&ddZd'ddZd(ddZddZd)ddZdd Zejejejejejfd!d"Zd#S)*URIMixinz0Mixin with all shared methods for URIs and IRIs.cCs||jsddddS|j}|dkr6tj|jj|j|j}|jd}|rxtj j |rxt j | rxtj|jj|j|S)aReturn 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)userinfohostportr ) authority_match_subauthorityexcInvalidAuthorityencodeencoding groupdictgetrZ IPv4_MATCHERmatchrZvalid_ipv4_host_address)selfrmatchesr rB/tmp/pip-build-el9acr48/urllib3/urllib3/packages/rfc3986/_mixin.pyauthority_infos    zURIMixin.authority_infocCstjj|jS)N)rZSUBAUTHORITY_MATCHERrr )rrrrr 5szURIMixin._match_subauthorityc Cs,y |j}Wntjk r"dSX|dS)z+If present, a string representing the host.Nr )rr r)rr rrrr 8s  z URIMixin.hostc Cs,y |j}Wntjk r"dSX|dS)z2If present, the port extracted from the authority.Nr )rr r)rr rrrr As  z URIMixin.portc Cs,y |j}Wntjk r"dSX|dS)z6If present, the userinfo extracted from the authority.Nr)rr r)rr rrrrJs  zURIMixin.userinfocCsttjj|jS)zDetermine 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_MATCHERrunsplit)rrrr is_absoluteSszURIMixin.is_absolutecKsrtjdt|j|jddf|j|jddf|j|jddf|j|jddf|j|jddfg}t dd |DS) 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).0vrrrr {sz$URIMixin.is_valid..) warningswarnDeprecationWarningscheme_is_validrauthority_is_valid path_is_validquery_is_validfragment_is_validall)rkwargsrrrris_valid]szURIMixin.is_validFc CsDtjdty |jWntjk 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_validcCstjdttj|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_validcCstjdttj|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_validcCstjdttj|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_validcCstjdttj|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|jt|jkS)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_refrrrnormalized_equalityszURIMixin.normalized_equalitycCst|tst|j|}|js*tj||j}|}| rT|j|jkrT|j dd}|jdk rt|j t j |j d}n|j dk r|j |jt j |j d}n|j dkr|jdk r|j}n|j}|j |j|j |j |d}nF|j jdrt j |j }nt j tj||j }|j |j|j ||jd}|S)aUse 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./) isinstancertypeZ from_stringrr ResolutionErrorr1r, copy_withrnormalize_pathr-r r. startswithrZ merge_paths)rZbase_uristrictZ resolvingtargetr.r-rrr resolve_withsD          zURIMixin.resolve_withcCsg}|jr|j|jdg|jr0|jd|jg|jrB|j|j|jdk r\|jd|jg|jdk rv|jd|jgdj|S)zCreate 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|jD]\}}|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/)listitemsr UseExisting_replacer) rr,r r-r.r/ attributeskeyvalueurirrrr7As   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 rrrobjectrrrrrs