
    j'                         d Z ddlmZ ddlmZ dedeeef         fdZedefd            Zedefd            Zedefd	            Z	edefd
            Z
dS )zSpain.    )Dict)	validatorvaluenumber_by_letterc                    t          |           dk    rdS |                                 } d}|                    | d         | d                   | dd         z   }|                                o!| d         |t	          |          dz           k    S )z&Validate if the doi is a NIF or a NIE.	   FTRWAGMYFPDXBNJZSQVHLCKEr            )lenuppergetisdigitint)r   r   tablenumberss       U/var/www/html/Carbon-Document/venv/lib/python3.11/site-packages/validators/i18n/es.py_nif_nie_validationr   
   s    
5zzQuKKMME%E ""58U1X66qsCG??EqU3w<<"3D-E!EE    c                   | rt          |           dk    rdS |                                 } d}| d         }| dd         }| d         }|                                sdS dt          d t	          |          D                       dz  z
  dz  }|d	v rt          |          |k    S |d
v r||         |k    S |dv r|t          |          ||         hv ndS )a  Validate a Spanish CIF.

    Each company in Spain prior to 2008 had a distinct CIF and has been
    discontinued. For more information see [wikipedia.org/cif][1].

    The new replacement is to use NIF for absolutely everything. The issue is
    that there are "types" of NIFs now: company, person [citizen or resident]
    all distinguished by the first character of the DOI. For this reason we
    will continue to call CIFs NIFs, that are used for companies.

    This validator is based on [generadordni.es][2].

    [1]: https://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
    [2]: https://generadordni.es/

    Examples:
        >>> es_cif('B25162520')
        True
        >>> es_cif('B25162529')
        ValidationError(func=es_cif, args={'value': 'B25162529'})

    Args:
        value:
            DOI string which is to be validated.

    Returns:
        (Literal[True]): If `value` is a valid DOI string.
        (ValidationError): If `value` is an invalid DOI string.
    r   F
JABCDEFGHIr   r
   r   
   c              3      K   | ]^\  }}|d z  dk    r?t          t          t          t          t          |          d z                                nt          |          V  _dS )   r   N)summapr   str).0indexchars      r   	<genexpr>zes_cif.<locals>.<genexpr>A   sw       
 
 t 27aCCSYY]++,,---SYY
 
 
 
 
 
r   ABEHPSQW	CDFGJNRUV)r   r   r   r   	enumerater   )r   r   	first_chrdoi_bodycontrolress         r   es_cifr+      s   >  CJJ!OOuKKMMEEaIQqSzHAhG u

 
 
  )22	
 
 
 
 
 	 		C F3xx7""FSzW$$09[0H0H7s3xxs,,,eSr   c                .    dddd}t          | |          S )a  Validate a Spanish NIF.

    Each entity, be it person or company in Spain has a distinct NIF. Since
    we've designated CIF to be a company NIF, this NIF is only for person.
    For more information see [wikipedia.org/nif][1]. This validator
    is based on [generadordni.es][2].

    [1]: https://es.wikipedia.org/wiki/N%C3%BAmero_de_identificaci%C3%B3n_fiscal
    [2]: https://generadordni.es/

    Examples:
        >>> es_nif('26643189N')
        True
        >>> es_nif('26643189X')
        ValidationError(func=es_nif, args={'value': '26643189X'})

    Args:
        value:
            DOI string which is to be validated.

    Returns:
        (Literal[True]): If `value` is a valid DOI string.
        (ValidationError): If `value` is an invalid DOI string.
    0)LMKr   r   r   s     r   es_nifr3   P   s%    4 !s55u&6777r   c                J    dddd}| r| d         |v rt          | |          S dS )u  Validate a Spanish NIE.

    The NIE is a tax identification number in Spain, known in Spanish
    as the NIE, or more formally the Número de identidad de extranjero.
    For more information see [wikipedia.org/nie][1]. This validator
    is based on [generadordni.es][2].

    [1]: https://es.wikipedia.org/wiki/N%C3%BAmero_de_identidad_de_extranjero
    [2]: https://generadordni.es/

    Examples:
        >>> es_nie('X0095892M')
        True
        >>> es_nie('X0095892X')
        ValidationError(func=es_nie, args={'value': 'X0095892X'})

    Args:
        value:
            DOI string which is to be validated.

    Returns:
        (Literal[True]): If `value` is a valid DOI string.
        (ValidationError): If `value` is an invalid DOI string.
    r-   12)XYZr   Fr1   r2   s     r   es_nier:   n   sA    4 !s55 <q---"5*:;;;5r   c                \    t          |           pt          |           pt          |           S )a  Validate a Spanish DOI.

    A DOI in spain is all NIF / CIF / NIE / DNI -- a digital ID.
    For more information see [wikipedia.org/doi][1]. This validator
    is based on [generadordni.es][2].

    [1]: https://es.wikipedia.org/wiki/Identificador_de_objeto_digital
    [2]: https://generadordni.es/

    Examples:
        >>> es_doi('X0095892M')
        True
        >>> es_doi('X0095892X')
        ValidationError(func=es_doi, args={'value': 'X0095892X'})

    Args:
        value:
            DOI string which is to be validated.

    Returns:
        (Literal[True]): If `value` is a valid DOI string.
        (ValidationError): If `value` is an invalid DOI string.
    )r:   r3   r+   )r   s    r   es_doir<      s&    2 %==:F5MM:VE]]:r   N)__doc__typingr   validators.utilsr   r   r   r+   r3   r:   r<    r   r   <module>rA      s          ' & & & & &
Fs 
Fd38n 
F 
F 
F 
F 5T# 5T 5T 5T 5Tp 8# 8 8 8 8: #    @ ;# ; ; ; ; ; ;r   