
    	a3                     T    d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ  G d d	      Zy)
z;Module containing the implementation of the URIMixin class.    N   )
exceptions)misc)normalizers)
validatorsc                   "   e Zd ZdZej
                  Zd Zd Zed        Z	ed        Z
ed        Zd Zd Zdd	Zdd
ZddZddZddZd ZddZd Zej.                  ej.                  ej.                  ej.                  ej.                  fdZy)URIMixinz0Mixin with all shared methods for URIs and IRIs.c                    | j                   sddddS | j                         }|8t        j                  | j                   j	                  | j
                              |j                         }|j                  d      }|rlt        j                  j                  |      rMt        j                  |      s8t        j                  | j                   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getr   IPv4_MATCHERmatchr   valid_ipv4_host_address)selfr   matchesr   s       0/usr/lib/python3/dist-packages/rfc3986/_mixin.pyauthority_infozURIMixin.authority_info   s     ~~ $dDAA((*=
 &&t~~'<'<T]]'KLL //#{{6" !!''-66t< &&t~~'<'<T]]'KLL    c                 T    t         j                  j                  | j                        S N)r   SUBAUTHORITY_MATCHERr   r   r   s    r   r   zURIMixin._match_subauthority8   s    ((..t~~>>r   c                 `    	 | j                         }|d   S # t        j                  $ r Y yw xY w)z+If present, a string representing the host.Nr   r   r   r   r   r   s     r   r   zURIMixin.host;   <    	++-I    ## 		    --c                 `    	 | j                         }|d   S # t        j                  $ r Y yw xY w)z2If present, the port extracted from the authority.Nr   r#   r$   s     r   r   zURIMixin.portD   r%   r&   c                 `    	 | j                         }|d   S # t        j                  $ r Y yw xY w)z6If present, the userinfo extracted from the authority.Nr   r#   r$   s     r   r   zURIMixin.userinfoM   s<    	++-I $$ ## 		r&   c                 n    t        t        j                  j                  | j	                                     S )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
        )boolr   ABSOLUTE_URI_MATCHERr   unsplitr!   s    r   is_absolutezURIMixin.is_absoluteV   s&     D--33DLLNCDDr   c           	         t        j                  dt               | j                  |j	                  dd      f| j
                  |j	                  dd      f| j                  |j	                  dd      f| j                  |j	                  dd      f| j                  |j	                  dd      fg}t        d |D              S )	ab  Determine 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
        XPlease use rfc3986.validators.Validator instead. This method will be eventually removed.require_schemeFrequire_authorityrequire_pathrequire_queryrequire_fragmentc              3   2   K   | ]  \  }} ||        y wr    ).0vrs      r   	<genexpr>z$URIMixin.is_valid.<locals>.<genexpr>   s     /DAq1Q4/s   )
warningswarnDeprecationWarningscheme_is_validr   authority_is_validpath_is_validquery_is_validfragment_is_validall)r   kwargsr   s      r   is_validzURIMixin.is_valid`   s    ( 	6	
 !!6::.>#FG$$fjj1De&LMNE!BC  &**_e"DE##VZZ0BE%JK

 /J///r   c                     t        j                  dt               	 | j                          t        j                  | j                  | j                  |      S # t        j
                  $ r Y yw xY w)a  Determine 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
        r/   F)r   require)
r;   r<   r=   r   r   r   r   r?   r   r   r   rG   s     r   r?   zURIMixin.authority_is_valid   si     	6	

	! ,,NN
 	
 ## 		s   A A.-A.c                 v    t        j                  dt               t        j                  | 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
        r/   )r;   r<   r=   r   r>   schemerH   s     r   r>   zURIMixin.scheme_is_valid   s1     	6	

 ))$++w??r   c                 v    t        j                  dt               t        j                  | 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
        r/   )r;   r<   r=   r   r@   pathrH   s     r   r@   zURIMixin.path_is_valid   s1     	6	

 ''		7;;r   c                 v    t        j                  dt               t        j                  | 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
        r/   )r;   r<   r=   r   rA   queryrH   s     r   rA   zURIMixin.query_is_valid   s1     	6	

 ((W==r   c                 v    t        j                  dt               t        j                  | j
                  |      S )aG  Determine 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
        r/   )r;   r<   r=   r   rB   fragmentrH   s     r   rB   zURIMixin.fragment_is_valid   s1     	6	

 ++DMM7CCr   c                 h    t        | j                               t        |j                               k(  S )a  Compare 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)r   	other_refs     r   normalized_equalityzURIMixin.normalized_equality   s)     T^^%&%	0C0C0E*FFFr   c                 >   t        |t              st        |       j                  |      }|j	                  d      st        j                  |      |j                         }| }|s+|j                  |j                  k(  r|j                  d      }|j                  1|j                  t        j                  |j                              }|S |j                  <|j                  |j                  t        j                  |j                              }|S |j                  Z|j                  |j                  }n|j                  }|j                  |j                  |j                  |j                  |      }|S |j                  j                  d      r t        j                  |j                        }n3t        j                  t!        j"                  ||j                              }|j                  |j                  |j                  ||j                        }|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`` does not at least have a scheme.
        T)r0   N)rJ   )rL   )rJ   rL   )rJ   r   rL   rN   /)
isinstancer	   typefrom_stringrE   r   ResolutionErrorrS   rJ   	copy_withr   normalize_pathrL   r   rN   
startswithr   merge_paths)r   base_uristrict	resolvingtargetrN   rL   s          r   resolve_withzURIMixin.resolve_with   s     (H-Dz--h7H   5%%h// %%' 	)**hoo=!++4+8I '(( //	? ) FD = "".",,#??$33INNC - : 1 >>) 2 ) (&00'"*"4"4%]]#	 1 F&  !~~005*99)..I*99 ,,Xy~~F  '00'"*"4"4!'oo	 1 F r   c                    g }| j                   r|j                  | j                   dg       | j                  r|j                  d| j                  g       | j                  r|j	                  | j                         | j
                  |j                  d| j
                  g       | j                  |j                  d| j                  g       dj                  |      S )zCreate a URI string from the components.

        :returns: The URI Reference reconstituted as a string.
        :rtype: str
        :z//?# )rJ   extendr   rL   appendrN   rP   join)r   result_lists     r   r,   zURIMixin.unsplit<  s     ;;S12>>dnn5699tyy)::!TZZ01==$T]]34ww{##r   c                     |||||d}t        |j                               D ]  \  }}|t        j                  u s||=   | j                  di |}	| j
                  |	_        |	S )a  Create 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
        )rJ   r   rL   rN   rP   r6   )listitemsr   UseExisting_replacer   )
r   rJ   r   rL   rN   rP   
attributeskeyvalueuris
             r   r\   zURIMixin.copy_withP  sw    4 " 

 z//12 	$JC(((sO	$ dmm)j)}}
r   N)F)__name__
__module____qualname____doc__rR   __hash__r   r   propertyr   r   r   r-   rE   r?   r>   r@   rA   rB   rU   rd   r,   r   rq   r\   r6   r   r   r	   r	   
   s    :~~H'R? ! ! ! ! % %E 0D
<@&<&>&D&GDL$, ""!!%r   r	   )	rz   r;   ri   r   r   r   r   r   r	   r6   r   r   <module>r}      s#    A     k kr   