o
    h3                     @   sP   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	 d	eZ	dS )
z;Module containing the implementation of the URIMixin class.    N   )
exceptions)misc)normalizers)
validatorsc                   @   s   e Zd ZdZejZdd Zdd Zedd Z	edd	 Z
ed
d Zdd Zdd Zd$ddZd$ddZd$ddZd$ddZd$ddZdd Zd$ddZdd  Zejejejejejfd!d"Zd#S )%URIMixinz0Mixin with all shared methods for URIs and IRIs.c                 C   sz   | j s	ddddS |  }|du rt| j | j| }|d}|r;tj	
|r;t|s;t| 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   ZIPv4_MATCHERmatchr   Zvalid_ipv4_host_address)selfr   matchesr	    r   V/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/rfc3986/_mixin.pyauthority_info   s   

zURIMixin.authority_infoc                 C   s   t j| jS N)r   ZSUBAUTHORITY_MATCHERr   r   r   r   r   r   r   8   s   zURIMixin._match_subauthorityc                 C   *   z	|   }W |d S  tjy   Y dS w )z+If present, a string representing the host.Nr	   r   r   r   r   r   r   r   r   r	   ;      
zURIMixin.hostc                 C   r   )z2If present, the port extracted from the authority.Nr
   r   r   r   r   r   r
   D   r   zURIMixin.portc                 C   r   )z6If present, the userinfo extracted from the authority.Nr   r   r   r   r   r   r   M   r   zURIMixin.userinfoc                 C   s   t t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   ZABSOLUTE_URI_MATCHERr   unsplitr   r   r   r   is_absoluteV   s   zURIMixin.is_absolutec              	   K   sr   t dt | j|ddf| j|ddf| j|ddf| j|ddf| j|ddfg}t	d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.Zrequire_schemeFZrequire_authorityZrequire_pathZrequire_queryZrequire_fragmentc                 s   s    | ]	\}}||V  qd S r   r   ).0vrr   r   r   	<genexpr>   s    z$URIMixin.is_valid.<locals>.<genexpr>)
warningswarnDeprecationWarningscheme_is_validr   authority_is_validpath_is_validquery_is_validfragment_is_validall)r   kwargsr   r   r   r   is_valid`   s   zURIMixin.is_validFc                 C   sD   t dt z|   W n tjy   Y dS w tj| j| j	|dS )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   r2   r   r   r   r+      s   zURIMixin.authority_is_validc                 C      t dt 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
        r"   )r'   r(   r)   r   r*   schemer3   r   r   r   r*      
   zURIMixin.scheme_is_validc                 C   r4   )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,   pathr3   r   r   r   r,      r6   zURIMixin.path_is_validc                 C   r4   )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   r-   queryr3   r   r   r   r-      r6   zURIMixin.query_is_validc                 C   r4   )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   r.   fragmentr3   r   r   r   r.      r6   zURIMixin.fragment_is_validc                 C   s   t |  t | 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   Z	other_refr   r   r   normalized_equality   s   zURIMixin.normalized_equalityc                 C   s"  t |tst| |}| st|| }| }|s)|j|jkr)|j	dd}|jdur:|j	t
|jd}|S |jdurM|j	|jt
|jd}|S |jdu rl|jdur[|j}n|j}|j	|j|j|j|d}|S |jdryt
|j}n
t
t||j}|j	|j|j||jd}|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)r5   )r7   )r5   r7   )r5   r   r7   r8   /)
isinstancer   typeZfrom_stringr!   r   ResolutionErrorr;   r5   	copy_withr   normalize_pathr7   r   r8   
startswithr   Zmerge_paths)r   Zbase_uristrictZ	resolvingtargetr8   r7   r   r   r   resolve_with   sT   



"



zURIMixin.resolve_withc                 C   s   g }| j r|| j dg | jr|d| jg | jr!|| j | jdur.|d| jg | jdur;|d| jg d|S )zCreate a URI string from the components.

        :returns: The URI Reference reconstituted as a string.
        :rtype: str
        :z//N?# )r5   extendr   r7   appendr8   r9   join)r   Zresult_listr   r   r   r    <  s   


zURIMixin.unsplitc           
      C   sR   |||||d}t | D ]\}}|tju r||= q| 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
        )r5   r   r7   r8   r9   Nr   )listitemsr   UseExisting_replacer   )
r   r5   r   r7   r8   r9   
attributeskeyvalueurir   r   r   rA   P  s   
zURIMixin.copy_withN)F)__name__
__module____qualname____doc__r:   __hash__r   r   propertyr	   r
   r   r!   r1   r+   r*   r,   r-   r.   r<   rF   r    r   rP   rA   r   r   r   r   r   
   s6    )




"





Fr   )
rY   r'   rJ   r   r   r   r   r   objectr   r   r   r   r   <module>   s    