
    01i6                         S r SSKJr  SSKJr  SSKJr   " S S\5      rS rS rS	 r	S
 r
SS jrSS jrSS jrSS jrSS jrSS jrS r\\\\S.r\" / SQ5      rS rS rg)z3Module containing the validation logic for rfc3986.   )
exceptions)misc)normalizersc                   b    \ rS rSrSr\" / SQ5      rS rS rS r	S r
S rS	 rS
 rS rS rSrg)	Validator   a?  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                     [        5       U l        [        5       U l        [        5       U l        SU l        SSSSSSSS.U l        U R
                  R                  5       U l        g)z#Initialize our default validations.TFr	   N)setallowed_schemesallowed_hostsallowed_portsallow_passwordrequired_componentscopyvalidated_componentsselfs    L/home/james-whalen/.local/lib/python3.13/site-packages/rfc3986/validators.py__init__Validator.__init__4   s`    "u U U"$
  %)$<$<$A$A$C!    c                 v    U H2  nU R                   R                  [        R                  " U5      5        M4     U $ )zRequire 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_schemesValidator.allow_schemesE   s2     F  $$[%A%A&%IJ r   c                 v    U H2  nU R                   R                  [        R                  " U5      5        M4     U $ )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_hostsValidator.allow_hostsU   s2     D"";#=#=d#CD r   c                     U H;  n[        USS9nSUs=::  a  S::  d  M  O  M   U R                  R                  U5        M=     U $ )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_portsValidator.allow_portse   sE     D4b)HH%%%""&&t,  r   c                     SU l         U $ )z~Allow passwords to be present in the URI.

.. versionadded:: 1.0

:returns:
    The validator instance.
:rtype:
    Validator
Tr   r   s    r   allow_use_of_passwordValidator.allow_use_of_passwordw   s     #r   c                     SU l         U $ )zPrevent passwords from being included in the URI.

.. versionadded:: 1.0

:returns:
    The validator instance.
:rtype:
    Validator
Fr7   r   s    r   forbid_use_of_password Validator.forbid_use_of_password   s     $r   c                    U Vs/ s H  o"R                  5       PM     nnU H,  nX0R                  ;  d  M  [        SR                  U5      5      e   U R                  R                  U Vs0 s H  o3S_M     sn5        U $ s  snf s  snf )zCheck 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
"{}" is not a valid componentT)lowerCOMPONENT_NAMES
ValueErrorformatr   updater   
componentsc	components       r   check_validity_ofValidator.check_validity_of   s     *44Aggi
4#I 4 44 3::9E  $
 	!!((.89j_j9	
  5 :   B +Bc                    U Vs/ s H  o"R                  5       PM     nnU H,  nX0R                  ;  d  M  [        SR                  U5      5      e   U R                  R                  U Vs0 s H  o3S_M     sn5        U $ s  snf s  snf )zRequire 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
r>   T)r?   r@   rA   rB   r   rC   rD   s       r   require_presence_ofValidator.require_presence_of   s     *44Aggi
4#I 4 44 3::9E  $
 	  ''.89j_j9	
  5 :rJ   c                    U R                   (       d  [        U5        U R                  R                  5        VVs/ s H  u  p#U(       d  M  UPM     nnnU R                  R                  5        VVs/ s H  u  p#U(       d  M  UPM     nnnU(       a  [        X5        U(       a  [        X5        [        U R                  US5        [        U R                  US5        [        U R                  US5        gs  snnf s  snnf )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.
r
   r   r   N)r   check_passwordr   itemsr    ensure_required_components_existensure_components_are_validensure_one_ofr   r   r   )r   urirG   requiredr   r   s         r   validateValidator.validate   s    & ""3 (,'?'?'E'E'G
'G#	 'G 	 
 (,'@'@'F'F'H 
'H#	 'H 	  

 ,SF'Bd**C:d((#v6d((#v6#

 
s   C5C51C;C;)r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__	frozensetr@   r   r$   r)   r4   r8   r;   rH   rL   rV   __static_attributes__ r   r   r   r      sD    4  KOD"  $22'7r   r   c                     U R                   nU(       d  gUR                  SS5      n[        U5      S::  a  g[        R                  " U 5      e)z4Assert that there is no password present in the uri.N:r   )r   splitlenr   PasswordForbidden)rT   r   credentialss      r   rO   rO      sB    ||H..a(K
;1

&
&s
++r   c                 l    [        X5      nUb&  U (       a  X0;  a  [        R                  " UUU 5      eggg)z=Assert that the uri's attribute is one of the allowed values.N)getattrr   UnpermittedComponentError)allowed_valuesrT   	attributevalues       r   rS   rS      s@    C#E^0K22
 	
 1L^r   c           	          [        U Vs/ s H  n[        X5      b  M  UPM     sn5      nU(       a  [        R                  " U /UQ76 egs  snf )z;Assert that all required components are present in the URI.N)sortedrg   r   MissingComponentError)rT   r   rG   missing_componentss       r   rQ   rQ     sX     1	
0	s& 0	
 ..sH5GHH 	
s
   A
A
c                     U(       a  U SL=(       a    UR                  U 5      $ U SL =(       d    UR                  U 5      $ )zDetermine 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)rk   matcherrequires      r   is_validrt     s:     D 9W]]5%99 D=0GMM%00r   Nc                 f    [        U [        R                  U5      nU(       a  Ub  [        X5      $ U$ )aB  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
)rt   r   SUBAUTHORITY_MATCHERhost_is_valid)	authorityr   rs   	validateds       r   authority_is_validrz   !  s1     D$=$=wGIT%T++r   c                 L   [        U [        R                  U5      nU(       a2  U b/  [        R                  R	                  U 5      (       a  [        U 5      $ U(       aH  U bE  [        R                  R	                  U 5      (       a!  [        R                  R	                  U 5      SL$ U$ )zDetermine 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)rt   r   HOST_MATCHERIPv4_MATCHERrq   valid_ipv4_host_addressIPv6_MATCHERIPv6_NO_RFC4007_MATCHER)r   rs   ry   s      r   rw   rw   5  s     t00':IT%$*;*;*A*A$*G*G&t,,	t'D,=,=,C,CD,I,I++11$7tCCr   c                 8    [        U [        R                  U5      $ )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
)rt   r   SCHEME_MATCHER)r
   rs   s     r   scheme_is_validr   I  s     FD//99r   c                 8    [        U [        R                  U5      $ )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
)rt   r   PATH_MATCHER)r   rs   s     r   path_is_validr   X  s     D$++W55r   c                 8    [        U [        R                  U5      $ )a  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
)rt   r   QUERY_MATCHER)r   rs   s     r   query_is_validr   g  s     E4--w77r   c                 8    [        U [        R                  U5      $ )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
)rt   r   FRAGMENT_MATCHER)r   rs   s     r   fragment_is_validr   v  s     Hd33W==r   c                     [        U R                  S5       Vs/ s H   nS[        USS9s=:*  =(       a    S:*  Os  PM"     sn5      $ s  snf )z4Determine if the given host is a valid IPv4 address..r/   r,   r-      )allrb   r1   )r   bytes     r   r~   r~     s=     4::c?K?4SB'..3.?KLLKs   'A)r
   r   r   r   )r   r   r   c                      U R                  5       nUS:X  a  [        US   5      $ US:w  a  g [	        US   5      nSUs=:*  =(       a    S:*  $ s  $ ! [        R                   a     gf = f! [
         a     gf = f)z4Determine if the userinfo, host, and port are valid.Fr   r   Tr/   r0   )authority_infor   InvalidAuthorityrw   r1   	TypeError)rT   rG   subauthority_dictr   s       r   subauthority_component_is_validr     s    ..0 F.v677	f	$V,- # &&    s"   A A+ A('A(+
A87A8c                 &   [        / 5      nU Hb  nU[        ;   a#  [        X5      (       d  UR                  U5        M0  [        U   nU" [        X5      5      (       a  MQ  UR                  U5        Md     U(       a  [        R                  " U /UQ76 eg)z0Assert that all components are valid in the URI.N)r   _SUBAUTHORITY_VALIDATORSr   r!   _COMPONENT_VALIDATORSrg   r   InvalidComponentsError)rT   r   invalid_componentsrG   	validators        r   rR   rR     s    R)	0023BB"&&y1 ))4	011""9- * //I6HII r   )NF)F)r\    r   r   r   objectr   rO   rS   rQ   rt   rz   rw   r   r   r   r   r~   r   r   r   r   rR   r_   r   r   <module>r      s    :   U7 U7p,

I1"((:68>M !	  ;< 0Jr   