
    }Wh6                         d Z ddlmZ ddlmZ ddlmZ  G d de          Zd Zd Zd	 Z	d
 Z
ddZddZddZddZddZddZd ZeeeedZ eg d          Zd Zd ZdS )z3Module containing the validation logic for rfc3986.   )
exceptions)misc)normalizersc                   b    e Zd ZdZ eg d          Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd ZdS )	Validatora  Object used to configure validation of all objects in rfc3986.

    .. versionadded:: 1.0

    Example usage::

         >>> from rfc3986 import api, validators
         >>> uri = api.uri_reference('https://github.com/')
         >>> validator = validators.Validator().require_presence_of(
         ...    'scheme', 'host', 'path',
         ... ).allow_schemes(
         ...    'http', 'https',
         ... ).allow_hosts(
         ...    '127.0.0.1', 'github.com',
         ... )
         >>> validator.validate(uri)
         >>> invalid_uri = rfc3986.uri_reference('imap://mail.google.com')
         >>> validator.validate(invalid_uri)
         Traceback (most recent call last):
         ...
         rfc3986.exceptions.MissingComponentError: ('path was required but
         missing', URIReference(scheme=u'imap', authority=u'mail.google.com',
         path=None, query=None, fragment=None), ['path'])

    schemeuserinfohostportpathqueryfragmentc                     t                      | _        t                      | _        t                      | _        d| _        dddddddd| _        | j                                        | _        dS )z#Initialize our default validations.TFr   N)setallowed_schemesallowed_hostsallowed_portsallow_passwordrequired_componentscopyvalidated_componentsselfs    X/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/rfc3986/validators.py__init__zValidator.__init__4   sq    "uu UU UU"$
 $
  %)$<$A$A$C$C!!!    c                 h    |D ].}| j                             t          j        |                     /| S )a	  Require the scheme to be one of the provided schemes.

        .. versionadded:: 1.0

        :param schemes:
            Schemes, without ``://`` that are allowed.
        :returns:
            The validator instance.
        :rtype:
            Validator
        )r   addr   normalize_scheme)r   schemesr	   s      r   allow_schemeszValidator.allow_schemesE   s?      	K 	KF $$[%A&%I%IJJJJr   c                 h    |D ].}| j                             t          j        |                     /| S )zRequire the host to be one of the provided hosts.

        .. versionadded:: 1.0

        :param hosts:
            Hosts that are allowed.
        :returns:
            The validator instance.
        :rtype:
            Validator
        )r   r   r   normalize_host)r   hostsr   s      r   allow_hostszValidator.allow_hostsU   s?      	E 	ED"";#=d#C#CDDDDr   c                     |D ]=}t          |d          }d|cxk    rdk    rn #| j                            |           >| S )zRequire the port to be one of the provided ports.

        .. versionadded:: 1.0

        :param ports:
            Ports that are allowed.
        :returns:
            The validator instance.
        :rtype:
            Validator
        
   base      )intr   r   )r   portsr   port_ints       r   allow_portszValidator.allow_portse   sd      	- 	-D4b)))HH%%%%%%%%%"&&t,,,r   c                     d| _         | S )zAllow passwords to be present in the URI.

        .. versionadded:: 1.0

        :returns:
            The validator instance.
        :rtype:
            Validator
        Tr   r   s    r   allow_use_of_passwordzValidator.allow_use_of_passwordw   s     #r   c                     d| _         | S )zPrevent passwords from being included in the URI.

        .. versionadded:: 1.0

        :returns:
            The validator instance.
        :rtype:
            Validator
        Fr2   r   s    r   forbid_use_of_passwordz Validator.forbid_use_of_password   s     $r   c                     d |D             }|D ]-}|| j         vr"t          d                    |                    .| j                            d |D                        | S )aA  Check the validity of the components provided.

        This can be specified repeatedly.

        .. versionadded:: 1.1

        :param components:
            Names of components from :attr:`Validator.COMPONENT_NAMES`.
        :returns:
            The validator instance.
        :rtype:
            Validator
        c                 6    g | ]}|                                 S  lower.0cs     r   
<listcomp>z/Validator.check_validity_of.<locals>.<listcomp>        444Aaggii444r   "{}" is not a valid componentc                     i | ]}|d S Tr8   r<   	components     r   
<dictcomp>z/Validator.check_validity_of.<locals>.<dictcomp>       999Y999r   )COMPONENT_NAMES
ValueErrorformatr   updater   
componentsrD   s      r   check_validity_ofzValidator.check_validity_of   s     54444
# 	 	I 444 3::9EE   5 	!((99j999	
 	
 	
 r   c                     d |D             }|D ]-}|| j         vr"t          d                    |                    .| j                            d |D                        | S )a3  Require the components provided.

        This can be specified repeatedly.

        .. versionadded:: 1.0

        :param components:
            Names of components from :attr:`Validator.COMPONENT_NAMES`.
        :returns:
            The validator instance.
        :rtype:
            Validator
        c                 6    g | ]}|                                 S r8   r9   r;   s     r   r>   z1Validator.require_presence_of.<locals>.<listcomp>   r?   r   r@   c                     i | ]}|d S rB   r8   rC   s     r   rE   z1Validator.require_presence_of.<locals>.<dictcomp>   rF   r   )rG   rH   rI   r   rJ   rK   s      r   require_presence_ofzValidator.require_presence_of   s     54444
# 	 	I 444 3::9EE   5 	 ''99j999	
 	
 	
 r   c                    | j         st          |           d | j                                        D             }d | j                                        D             }|rt          ||           |rt          ||           t          | j        |d           t          | j	        |d           t          | j
        |d           dS )a  Check a URI for conditions specified on this validator.

        .. versionadded:: 1.0

        :param uri:
            Parsed URI to validate.
        :type uri:
            rfc3986.uri.URIReference
        :raises MissingComponentError:
            When a required component is missing.
        :raises UnpermittedComponentError:
            When a component is not one of those allowed.
        :raises PasswordForbidden:
            When a password is present in the userinfo component but is
            not permitted by configuration.
        :raises InvalidComponentsError:
            When a component was found to be invalid.
        c                     g | ]	\  }}||
S r8   r8   r<   rD   requireds      r   r>   z&Validator.validate.<locals>.<listcomp>   s2     
 
 
#	8

 
 
r   c                     g | ]	\  }}||
S r8   r8   rT   s      r   r>   z&Validator.validate.<locals>.<listcomp>   s2      
  
  
#	8 
 
  
  
r   r	   r   r   N)r   check_passwordr   itemsr    ensure_required_components_existensure_components_are_validensure_one_ofr   r   r   )r   urir   r   s       r   validatezValidator.validate   s    & " 	 3
 
'+'?'E'E'G'G
 
 

 
  
'+'@'F'F'H'H 
  
  

  	G,S2EFFF 	C'-ABBBd*C:::d(#v666d(#v66666r   N)__name__
__module____qualname____doc__	frozensetrG   r   r"   r&   r0   r3   r5   rM   rQ   r]   r8   r   r   r   r      s         4  iKKK OD D D"        $      2  2'7 '7 '7 '7 '7r   r   c                     | j         }|sdS |                    dd          }t          |          dk    rdS t          j        |           )z4Assert that there is no password present in the uri.N:r   )r
   splitlenr   PasswordForbidden)r\   r
   credentialss      r   rW   rW      sR    |H ..a((K
;1

&s
+
++r   c                 j    t          ||          }|| r|| vrt          j        |||           dS dS dS )z=Assert that the uri's attribute is one of the allowed values.N)getattrr   UnpermittedComponentError)allowed_valuesr\   	attributevalues       r   r[   r[      sX    C##E^^0K0K2
 
 	
 0K0Kr   c                 f     t           fd|D                       }|rt          j         g|R  dS )z;Assert that all required components are present in the URI.c                 4    g | ]}t          |          |S )N)rj   )r<   rD   r\   s     r   r>   z4ensure_required_components_exist.<locals>.<listcomp>  s3     	
 	
 	
sI&&. ...r   N)sortedr   MissingComponentError)r\   r   missing_componentss   `  r   rY   rY     sj    	
 	
 	
 	
0	
 	
 	
   I.sH5GHHHHI Ir   c                 j    |r| duo|                     |           S | du p|                     |           S )a  Determine if a value is valid based on the provided matcher.

    :param str value:
        Value to validate.
    :param matcher:
        Compiled regular expression to use to validate the value.
    :param require:
        Whether or not the value is required.
    N)match)rn   matcherrequires      r   is_validrx     sE      :D 9W]]5%9%99 D=0GMM%000r   NFc                 d    t          | t          j        |          }|r|t          ||          S |S )an  Determine if the authority string is valid.

    :param str authority:
        The authority to validate.
    :param str host:
        (optional) The host portion of the authority to validate.
    :param bool require:
        (optional) Specify if authority must not be None.
    :returns:
        ``True`` if valid, ``False`` otherwise
    :rtype:
        bool
    )rx   r   SUBAUTHORITY_MATCHERhost_is_valid)	authorityr   rw   	validateds       r   authority_is_validr~   !  s;     D$=wGGI ,T%T7+++r   c                 (   t          | t          j        |          }|r0| .t          j                            |           rt          |           S |rB| @t          j                            |           r!t          j                            |           duS |S )a  Determine if the host string is valid.

    :param str host:
        The host to validate.
    :param bool require:
        (optional) Specify if host must not be None.
    :returns:
        ``True`` if valid, ``False`` otherwise
    :rtype:
        bool
    N)rx   r   HOST_MATCHERIPv4_MATCHERru   valid_ipv4_host_addressIPv6_MATCHERIPv6_NO_RFC4007_MATCHER)r   rw   r}   s      r   r{   r{   5  s     t0'::I DT%$*;*A*A$*G*G%&t,,,	 Dt'D,=,C,CD,I,I'+11$77tCCr   c                 8    t          | t          j        |          S )a+  Determine if the scheme is valid.

    :param str scheme:
        The scheme string to validate.
    :param bool require:
        (optional) Set to ``True`` to require the presence of a scheme.
    :returns:
        ``True`` if the scheme is valid. ``False`` otherwise.
    :rtype:
        bool
    )rx   r   SCHEME_MATCHER)r	   rw   s     r   scheme_is_validr   I  s     FD/999r   c                 8    t          | t          j        |          S )a+  Determine if the path component is valid.

    :param str path:
        The path string to validate.
    :param bool require:
        (optional) Set to ``True`` to require the presence of a path.
    :returns:
        ``True`` if the path is valid. ``False`` otherwise.
    :rtype:
        bool
    )rx   r   PATH_MATCHER)r   rw   s     r   path_is_validr   X  s     D$+W555r   c                 8    t          | t          j        |          S )a0  Determine if the query component is valid.

    :param str query:
        The query string to validate.
    :param bool require:
        (optional) Set to ``True`` to require the presence of a query.
    :returns:
        ``True`` if the query is valid. ``False`` otherwise.
    :rtype:
        bool
    )rx   r   QUERY_MATCHER)r   rw   s     r   query_is_validr   g  s     E4-w777r   c                 8    t          | t          j        |          S )a?  Determine if the fragment component is valid.

    :param str fragment:
        The fragment string to validate.
    :param bool require:
        (optional) Set to ``True`` to require the presence of a fragment.
    :returns:
        ``True`` if the fragment is valid. ``False`` otherwise.
    :rtype:
        bool
    )rx   r   FRAGMENT_MATCHER)r   rw   s     r   fragment_is_validr   v  s     Hd3W===r   c                 Z    t          d |                     d          D                       S )z4Determine if the given host is a valid IPv4 address.c                 L    g | ]!}d t          |d          cxk    odk    nc "S )r+   r(   r)      )r-   )r<   bytes     r   r>   z+valid_ipv4_host_address.<locals>.<listcomp>  sA    KKK4SB'''....3....KKKr   .)allre   )r   s    r   r   r     s+     KK4::c??KKKLLLr   )r	   r   r   r   )r
   r   r   c                    	 |                                  }n# t          j        $ r Y dS w xY w|dk    rt          |d                   S |dk    rdS 	 t	          |d                   }n# t
          $ r Y dS w xY wd|cxk    odk    nc S )z4Determine if the userinfo, host, and port are valid.Fr   r   Tr+   r,   )authority_infor   InvalidAuthorityr{   r-   	TypeError)r\   rD   subauthority_dictr   s       r   subauthority_component_is_validr     s    ..00&   uu
 F.v6777	f		t$V,--    tt
 s    **A' '
A54A5c                 *   t          g           }|D ]l}|t          v r&t          | |          s|                    |           1t          |         } |t          | |                    s|                    |           m|rt          j        | g|R  dS )z0Assert that all components are valid in the URI.N)r   _SUBAUTHORITY_VALIDATORSr   r   _COMPONENT_VALIDATORSrj   r   InvalidComponentsError)r\   r   invalid_componentsrD   	validators        r   rZ   rZ     s    R) . .	00023	BB 2"&&y111 ))4	yi0011 	.""9--- J/I6HIIIIJ Jr   )NF)F)ra    r   r   r   objectr   rW   r[   rY   rx   r~   r{   r   r   r   r   r   r   r   r   r   rZ   r8   r   r   <module>r      s   : 9                  U7 U7 U7 U7 U7 U7 U7 U7p, , ,
 
 

I 
I 
I1 1 1"   (   (: : : :6 6 6 68 8 8 8> > > >M M M !	   3;;;<<   0J J J J Jr   