Ë
    Ã?ÆiO  ã                  ó^   — d Z ddlmZ ddl­ ddlmZ dZdd„Zdd„Zdd„Z	dd	„Z
dd
„Zdd„Zy)uú  Referencia Catastral (Spanish real estate property id)

The cadastral reference code is an identifier for real estate in Spain. It is
issued by DirecciÃ³n General del Catastro (General Directorate of Land
Registry) of the Ministerio de Hacienda (Tresury Ministry).

It has 20 digits and contains numbers and letters including the Spanish Ã‘.
The number consists of 14 digits for the parcel, 4 for identifying properties
within the parcel and 2 check digits. The parcel digits are structured
differently for urban, non-urban or special (infrastructure) cases.

More information:

* https://www.catastro.meh.es/ (Spanish)
* https://www.catastro.meh.es/documentos/05042010_P.pdf (Spanish)
* https://es.wikipedia.org/wiki/Catastro#Referencia_catastral

>>> validate('7837301-VG8173B-0001 TT')  # Lanteira town hall
'7837301VG8173B0001TT'
>>> validate('783301 VG8173B 0001 TT')  # missing digit
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> validate('7837301/VG8173B 0001 TT')  # not alphanumeric
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> validate('7837301 VG8173B 0001 NN')  # bad check digits
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> format('4A08169P03PRAT0001LR')  # BCN Airport
'4A08169 P03PRAT 0001 LR'
é    )Úannotations)Ú*)Úcleanu&   ABCDEFGHIJKLMNÃ‘OPQRSTUVWXYZ0123456789c                óR   — t        | d«      j                  «       j                  «       S )zˆConvert the number to the minimal representation. This strips the
    number of any valid separators and removes surrounding whitespace.z -)r   ÚstripÚupper©Únumbers    úd/var/www/html/myprovider/mon_projet_qr/lib/python3.12/site-packages/stdnum/es/referenciacatastral.pyÚcompactr   B   s#   € ô �˜Ó×$Ñ$Ó&×,Ñ,Ó.Ð.ó    c                óZ   — t        | «      } dj                  | dd | dd | dd | dd g«      S )z8Reformat the number to the standard presentation format.ú Né   é   é   )r   Újoinr	   s    r   Úformatr   H   sE   € ä�V‹_€FØ�8‰8Øˆr�ˆ
Øˆq�ˆØˆr�"ˆØˆrˆsˆð	ó ð r   c                óN   — d}t        d„ t        || «      D «       «      }d|dz     S )zBCalculate a single check digit on the provided part of the number.)é   é   é   é   é   é   é	   é   é   r   é   c              3  óŽ   K  — | ]=  \  }}||j                  «       rt        |«      nt        j                  |«      d z   z  –— Œ? y­w)r   N)ÚisdigitÚintÚalphabetÚfind)Ú.0ÚwÚns      r   ú	<genexpr>z_check_digit.<locals>.<genexpr>Y   s=   è ø€ ò .Ù��1ð ˜1Ÿ9™9œ;”�Q”¬H¯M©M¸!Ó,<¸qÑ,@ÕAñ .ùs   ‚AAÚMQWERTYUIOPASDFGHJKLBZXé   )ÚsumÚzip)r
   ÚweightsÚss      r   Ú_check_digitr/   V   s4   € à4€GÜñ .Ü˜G VÓ,ô.ó 	.€Aà$ Q¨¡VÑ,Ð,r   c                ój   — t        | «      } t        | dd | dd z   «      t        | dd | dd z   «      z   S )z*Calculate the check digits for the number.r   r   r   r   )r   r/   r	   s    r   Úcalc_check_digitsr1   ^   sG   € ä�V‹_€Fä�V˜A˜a�[ 6¨"¨R =Ñ0Ó1Ü�V˜A˜b�\ F¨2¨b MÑ1Ó2ñ	3ð4r   c                óº   — t        | «      } t        d„ | D «       «      s
t        «       ‚t        | «      dk7  r
t	        «       ‚t        | «      | dd k7  r
t        «       ‚| S )zlCheck if the number is a valid Cadastral Reference. This checks the
    length, formatting and check digits.c              3  ó,   K  — | ]  }|t         v –— Œ y ­w)N)r#   )r%   Úcs     r   r(   zvalidate.<locals>.<genexpr>j   s   è ø€ Ò- ˆq”HŒ}Ñ-ùs   ‚é   r   N)r   ÚallÚInvalidFormatÚlenÚInvalidLengthr1   ÚInvalidChecksumr	   s    r   Úvalidater;   f   sX   € ô �V‹_€FÜÑ- fÔ-Ô-Ü‹oÐÜ
ˆ6ƒ{�bÒÜ‹oÐÜ˜Ó  F¨2¨3 KÒ/ÜÓÐØ€Mr   c                óJ   — 	 t        t        | «      «      S # t        $ r Y yw xY w)z3Check if the number is a valid Cadastral Reference.F)Úboolr;   ÚValidationErrorr	   s    r   Úis_validr?   s   s)   € ðÜ”H˜VÓ$Ó%Ð%øÜò Ùðús   ‚ –	"¡"N)r
   ÚstrÚreturnr@   )r
   r@   rA   r=   )Ú__doc__Ú
__future__r   Ústdnum.exceptionsÚstdnum.utilr   r#   r   r   r/   r1   r;   r?   © r   r   ú<module>rG      s;   ðñ,!õF #ä Ý ð 4€ó/óó-ó4ó
ôr   