Ë
    Ã?Æi’  ã                  óŽ   — d Z ddlmZ ddlZddlZddl­ ddlmZmZ dd„Z	dd„Z
dd„Zdd	„Zdd
„Zdd„Zdd„Zdd„Zdd„Zdd„Zy)uH	  NN, NISS, RRN (Belgian national number).

The national registration number (Rijksregisternummer, NumÃ©ro de registre
national, Nationalregisternummer) is a unique identification number of
natural persons who are registered in Belgium.

The number consists of 11 digits and includes the person's date of birth and
gender. It encodes the date of birth in the first 6 digits in the format
YYMMDD. The following 3 digits represent a counter of people born on the same
date, seperated by sex (odd for male and even for females respectively). The
final 2 digits form a check number based on the 9 preceding digits.

Special cases include:

* Counter exhaustion:
  When the even or uneven day counter range for a specific date of birth runs
  out, (e.g. from 001 tot 997 for males), the first 2 digits will represent
  the birth year as normal, while the next 4 digits (birth month and day) are
  taken to be zeroes. The remaining 3 digits still represent a day counter
  which will then restart.
  When those ranges would run out also, the sixth digit is incremented with 1
  and the day counter will restart again.

* Incomplete date of birth
  When the exact month or day of the birth date were not known at the time of
  assignment, incomplete parts are taken to be zeroes, similarly as with
  counter exhaustion.
  Note that a month with zeroes can thus both mean the date of birth was not
  exactly known, or the person was born on a day were at least 500 persons of
  the same gender got a number assigned already.

* Unknown date of birth
  When no part of the date of birth was known, a fictitious date is used
  depending on the century (i.e. 1900/00/01 or 2000/00/01).

More information:

* https://nl.wikipedia.org/wiki/Rijksregisternummer
* https://fr.wikipedia.org/wiki/NumÃ©ro_de_registre_national
* https://www.ibz.rrn.fgov.be/fileadmin/user_upload/nl/rr/instructies/IT-lijst/IT000_Rijksregisternummer.pdf

>>> compact('85.07.30-033 28')
'85073003328'
>>> validate('85 07 30 033 28')
'85073003328'
>>> validate('17 07 30 033 84')
'17073003384'
>>> validate('12345678901')
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> format('85073003328')
'85.07.30-033.28'
>>> get_birth_date('85.07.30-033 28')
datetime.date(1985, 7, 30)
>>> get_birth_year('85.07.30-033 28')
1985
>>> get_birth_month('85.07.30-033 28')
7
>>> get_gender('85.07.30-033 28')
'M'
é    )ÚannotationsN)Ú*)ÚcleanÚisdigitsc                ó:   — t        | d«      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©Únumbers    úS/var/www/html/myprovider/mon_projet_qr/lib/python3.12/site-packages/stdnum/be/nn.pyÚcompactr   ^   s   € ô �6˜5Ó!×'Ñ'Ó)€FØ€Mó    c                ó.  — | g}t        | dd «      dz   t        j                  j                  «       j                  k  r|j                  d| z   «       t        d|«      D ],  \  }}dt        |dd «      dz  z
  t        |dd «      k(  sŒ*|c S  t        «       ‚)z7Calculate the checksum and return the detected century.Né   éÐ  Ú2)il  r   éa   éþÿÿÿ)ÚintÚdatetimeÚdateÚtodayÚyearÚappendÚzipÚInvalidChecksum)r
   ÚnumbersÚcenturyÚns       r   Ú	_checksumr   e   s“   € àˆh€GÜ
ˆ6�"�1ˆ:ƒ˜Ñ¤§¡×!4Ñ!4Ó!6×!;Ñ!;Ò;Ø�‰�s˜V‘|Ô$Ü˜,¨Ó0ò ‰
ˆ�Ø”�Q�s˜�V“˜rÑ!Ñ"¤c¨!¨B¨C¨&£kÓ1ØŠNðô Ó
Ðr   c                ó  — t        | «      }| dd dv ryt        | dd «      |z   }t        | dd «      dz  }t        | dd «      }|dk(  r|ddfS |d	kD  rt        d
«      ‚|dk(  s|t        j                  ||«      d   kD  r||dfS |||fS )z’Check if the number's encoded birth date is valid, and return the contained
    birth year, month and day of month, accounting for unknown values.Né   )Ú000001Ú002001Ú004001)NNNr   é   é   r   é   úMonth must be in 1..12é   )r   r   ÚInvalidComponentÚcalendarÚ
monthrange)r
   r   r   ÚmonthÚdays        r   Ú_get_birth_date_partsr/   p   sÂ   € ô ˜Ó€Gð
 ˆbˆq€zÐ3Ñ3Ø!äˆv�b�qˆz‹?˜WÑ$€DÜ��q˜�Ó˜rÑ!€EÜ
ˆf�Q�qˆkÓ
€Cð �‚zØ�d˜DÐ!Ð!ð ˆr‚zÜÐ7Ó8Ð8ð ˆa‚x�3œ×,Ñ,¨T°5Ó9¸!Ñ<Ò<Ø�e˜TÐ"Ð"à�%˜ÐÐr   c                ó  — t        | «      } t        | «      rt        | «      dk  r
t        «       ‚t	        | «      dk7  r
t        «       ‚t        | «       dt        | dd «      cxk  rdk  st        d«      ‚ t        d«      ‚| S )ú/Check if the number is a valid National Number.r   é   r   r%   r'   r(   )r   r   r   ÚInvalidFormatÚlenÚInvalidLengthr/   r*   r	   s    r   Úvalidater6   �   s|   € ä�V‹_€FÜ�FÔœs 6›{¨aÒ/Ü‹oÐÜ
ˆ6ƒ{�bÒÜ‹oÐÜ˜&Ô!Ø”�F˜1˜Q�KÓ Ô& BÒ&ÜÐ7Ó8Ð8ð 'ÜÐ7Ó8Ð8Ø€Mr   c                óJ   — 	 t        t        | «      «      S # t        $ r Y yw xY w)r1   F)Úboolr6   ÚValidationErrorr	   s    r   Úis_validr:   œ   s)   € ðÜ”H˜VÓ$Ó%Ð%øÜò Ùðús   ‚ –	"¡"c                óž   ‡ — t        ‰ «      Š dj                  ˆ fd„t        ddd«      D «       «      dz   dj                  ‰ dd ‰ dd g«      z   S )	z8Reformat the number to the standard presentation format.ú.c              3  ó.   •K  — | ]  }‰||d z    –— Œ y­w)r   N© )Ú.0Úir
   s     €r   ú	<genexpr>zformat.<locals>.<genexpr>¨   s   øè ø€ Ò9 Q�˜˜!˜a™%”Ñ9ùs   ƒr   r!   r   ú-é	   r2   )r   ÚjoinÚranger	   s   `r   ÚformatrF   ¤   sU   ø€ ä�V‹_€Fà�‰Ó9¬%°°1°a«.Ô9Ó9Øñ	Ø�h‰h˜˜q ˜ V¨A¨b \Ð2Ó3ñ	4ð5r   c                ó6   — t        t        | «      «      \  }}}|S )z"Return the year of the birth date.©r/   r   ©r
   r   r-   r.   s       r   Úget_birth_yearrJ   ¬   s   € ä,¬W°V«_Ó=Ñ€Dˆ%�Ø€Kr   c                ó6   — t        t        | «      «      \  }}}|S )z#Return the month of the birth date.rH   rI   s       r   Úget_birth_monthrL   ²   s   € ä,¬W°V«_Ó=Ñ€Dˆ%�Ø€Lr   c                ón   — t        t        | «      «      \  }}}|r|r|rt        j                  |||«      S y)zReturn the date of birth.N)r/   r   r   r   rI   s       r   Úget_birth_daterN   ¸   s4   € ä,¬W°V«_Ó=Ñ€Dˆ%�Ù‘™#Ü�}‰}˜T 5¨#Ó.Ð.Ør   c                ó>   — t        | «      } t        | dd «      dz  ryy)z%Get the person's gender ('M' or 'F').r!   rC   r   ÚMÚF)r   r   r	   s    r   Ú
get_genderrR   À   s$   € ä�V‹_€FÜ
ˆ6�!�Aˆ;Ó˜!ÒØØr   )r
   ÚstrÚreturnrS   )r
   rS   rT   r   )r
   rS   rT   z)tuple[int | None, int | None, int | None])r
   rS   rT   r8   )r
   rS   rT   z
int | None)r
   rS   rT   zdatetime.date | None)Ú__doc__Ú
__future__r   r+   r   Ústdnum.exceptionsÚstdnum.utilr   r   r   r   r/   r6   r:   rF   rJ   rL   rN   rR   r>   r   r   ú<module>rY      sN   ðñ,=õ~ #ã Û ä ß 'óóóó>
óó5óóóôr   