Ë
    Ã?Æi1  ã                  ó  — d Z ddlmZ ddlZddlZddlZddlmZ ddl­ ddl	m
Z
 dZerddlmZ dd	lmZ  ej                   d
«      Zdd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d$d%d„Zd&d'd„Zd$d(d„Zd$d)d„Zy)*aë  GS1-128 (Standard to encode product information in Code 128 barcodes).

The GS1-128 (also called EAN-128, UCC/EAN-128 or UCC-128) is an international
standard for embedding data such as best before dates, weights, etc. with
Application Identifiers (AI).

The GS1-128 standard is used as a product identification code on bar codes.
It embeds data with Application Identifiers (AI) that defines the kind of
data, the type and length. The standard is also known as UCC/EAN-128, UCC-128
and EAN-128.

GS1-128 is a subset of Code 128 symbology.

More information:

* https://en.wikipedia.org/wiki/GS1-128
* https://www.gs1.org/standards/barcodes/application-identifiers
* https://www.gs1.org/docs/barcodes/GS1_General_Specifications.pdf

>>> compact('(01)38425876095074(17)181119(37)1 ')
'013842587609507417181119371'
>>> encode({'01': '38425876095074'})
'0138425876095074'
>>> info('0138425876095074')
{'01': '38425876095074'}
>>> validate('(17)181119(01)38425876095074(37)1')
'013842587609507417181119371'
é    )ÚannotationsN)Únumdb)Ú*)ÚcleanF)ÚMapping)ÚAnyÚgs1_aiz
stdnum.eanzstdnum.iban)Ú01Ú02Ú8007c                ó6   — t        | d«      j                  «       S )zÜConvert the GS1-128 to the minimal representation.

    This strips the number of any valid separators and removes surrounding
    whitespace. For a more consistent compact representation use
    :func:`validate()`.
    z())r   Ústrip)Únumbers    úU/var/www/html/myprovider/mon_projet_qr/lib/python3.12/site-packages/stdnum/gs1_128.pyÚcompactr   O   s   € ô �˜Ó×$Ñ$Ó&Ð&ó    c                ón  — t        |t        t        f«      rJ|j                  d«      r9t	        | |dd |d   «      \  } }| t        |d   «      j                  dd«      |z   fS t        |«      }|j                  d«      rUt        |dd «      }|d|dz    }|j                  d«      d	gz   dd
 \  }}|dd }| dd t        t        |«      «      z   ||z   fS t        |dd «      }|d|dz    }|j                  d«      d	gz   dd
 \  }}|dd }| dd t        t        |«      «      z   ||z   j                  |d«      fS )z4Encode the specified decimal value given the format.úN3+é   Né   r   Ú0zN..ú.Ú é   é	   éÿÿÿÿ)
Ú
isinstanceÚlistÚtupleÚ
startswithÚ_encode_decimalÚstrÚrjustÚintÚsplitÚlen)ÚaiÚfmtÚvaluer   ÚlengthÚdecimalss         r   r!   r!   Y   sb  € ô �%œ$¤˜Ô'¨C¯N©N¸5Ô,Aô % R¨¨Q¨R¨°%¸±(Ó;‰
ˆˆFØ”3�u˜Q‘x“=×&Ñ& q¨#Ó.°Ñ7Ð7Ð7Ü�‹J€EØ
‡~�~�eÔä�S˜˜�W“ˆØ�k�v ‘zÐ"ˆØ!ŸK™K¨Ó,°¨tÑ3°R°aÐ8Ñˆ�Ø˜B˜Q�<ˆØ�#�2ˆwœœS ›]Ó+Ñ+¨V°hÑ->Ð>Ð>ô �S˜˜�W“ˆØ�k�v ‘zÐ"ˆØ!ŸK™K¨Ó,°¨tÑ3°R°aÐ8Ñˆ�Ø˜B˜Q�<ˆØ�#�2ˆwœœS ›]Ó+Ñ+¨f°xÑ.?×-FÑ-FÀvÈsÓ-SÐSÐSr   c                ó>  — t        |t        t        f«      r$| dv r t        d|d   «      ›t        d|d   «      ›�S t        |t        j
                  «      r¿| dv r|j                  d«      S | dk(  r|j                  d«      S | d	v r?|j                  d«      }|j                  d
«      r|dd }|j                  d
«      r|dd }|S | dv r?|j                  d«      }|j                  d
«      r|dd }|j                  d
«      r|dd }|S t        d| z  «      ‚t        |«      S )z1Encode the specified date value given the format.)úN6..12úN6[+N6]ÚN6r   r   )r/   r-   r.   ú%y%m%dÚN10z
%y%m%d%H%M)zN6+N..4z	N6[+N..4]zN6[+N4]Ú00Néþÿÿÿ)zN8+N..4z	N8[+N..4]ú%y%m%d%H%M%Szunsupported format: %s)
r   r   r   Ú_encode_dateÚdatetimeÚdateÚstrftimeÚendswithÚ
ValueErrorr"   )r(   r)   s     r   r5   r5   s   s/  € ä�%œ$¤˜Ô'¨CÐ3HÑ,Hô ˜˜u Q™xÔ(Ü˜˜u Q™xÔ(ð
ð 	
ô 
�Eœ8Ÿ=™=Ô	)àÐ-Ñ-Ø—>‘> (Ó+Ð+Ø�EŠ\Ø—>‘> ,Ó/Ð/ØÐ7Ñ7Ø—N‘N <Ó0ˆEØ�~‰~˜dÔ#Ø˜c˜r˜
�Ø�~‰~˜dÔ#Ø˜c˜r˜
�ØˆLØÐ,Ñ,Ø—N‘N >Ó2ˆEØ�~‰~˜dÔ#Ø˜c˜r˜
�Ø�~‰~˜dÔ#Ø˜c˜r˜
�ØˆLäÐ5¸Ñ;Ó<Ð<ô �5‹zÐr   c                óf   — |dk(  rt        | ||«      S |dk(  r| t        ||«      fS | t        |«      fS )z5Encode the specified value given the format and type.Údecimalr7   )r!   r5   r"   ©r'   r(   Ú_typer)   s       r   Ú_encode_valuer?   –   s@   € à�	ÒÜ˜r 3¨Ó.Ð.Ø	�&ŠØ”<  UÓ+Ð+Ð+à”3�u“:ˆ~Ðr   c                óD   — t        d„ | j                  d«      D «       «      S )z1Determine the maximum length based on the format.c              3  óx   K  — | ]2  }t        t        j                  d |«      j                  d«      «      –— Œ4 y­w)z!^[NXY][0-9]*?[.]*([0-9]+)[\[\]]?$r   N)r$   ÚreÚmatchÚgroup)Ú.0Úxs     r   ú	<genexpr>z_max_length.<locals>.<genexpr>¢   s4   è ø€ ò àô 	ŒB�H‰HÐ9¸1Ó=×CÑCÀAÓF×Gñùs   ‚8:ú+)Úsumr%   )r(   s    r   Ú_max_lengthrJ       s$   € äñ à—‘˜3“ôó ð r   c                ót   — |dv r|j                  t        | «      d«      S |j                  t        | «      «      S )z3Pad the value to the maximum length for the format.)r<   r$   r   )r#   rJ   Úljust)r(   r>   r)   s      r   Ú
_pad_valuerM   ¨   s5   € àÐ"Ñ"Ø�{‰{œ; sÓ+¨SÓ1Ð1à�{‰{œ; sÓ+Ó,Ð,r   c                ó¾   — |j                  d«      r|dd t        | |dd |dd «      fS t        | d   «      }|r|d|  dz   || d z   }t        j                  |«      S )z1Decode the specified decimal value given the fmt.r   Nr   r   r   )r    Ú_decode_decimalr$   r<   ÚDecimal)r'   r(   r)   r+   s       r   rO   rO   °   sv   € à
‡~�~�eÔð �b�q�	œ?¨2¨s°1°2¨w¸¸a¸b¸	ÓBÐCÐCÜ�2�b‘6‹{€HÙØ�j˜�yÐ! CÑ'¨%°°	°
Ð*;Ñ;ˆÜ�?‰?˜5Ó!Ð!r   c                óx  — t        |«      dk(  rÑ|dd dk(  r›t        j                  j                  |dd d«      }|j                  dk(  r"|j	                  d¬«      }|j                  «       S |j	                  |j                  d	z   d	¬
«      t        j
                  d	¬«      z
  }|j                  «       S t        j                  j                  |d«      j                  «       S t        |«      dk(  r"| dv rt        d|dd «      t        d|dd «      fS t        j                  j                  |ddt        |«       «      S )z.Decode the specified date value given the fmt.é   é   Nr2   z%y%mé   é   )Údayr   )ÚmonthrV   )Údaysr0   )ÚN12r-   r.   r/   r4   )r&   r6   ÚstrptimerW   ÚreplaceÚ	timedeltar7   Ú_decode_date)r(   r)   r7   s      r   r]   r]   ¼   s  € ä
ˆ5ƒz�Q‚Ø��ˆ9˜Òä×$Ñ$×-Ñ-¨e°B°Q¨i¸Ó@ˆDØ�z‰z˜RÒØ—|‘|¨�|Ó+�ð —9‘9“;Ðð —|‘|¨$¯*©*°q©.¸a�|Ó@Ä8×CUÑCUÐ[\ÔC]Ñ]�Ø—9‘9“;Ðä×$Ñ$×-Ñ-¨e°XÓ>×CÑCÓEÐEÜ	ˆU‹�rÒ	˜cÐ%AÑAÜ˜T 5¨¨! 9Ó-¬|¸DÀ%ÈÈÀ)Ó/LÐMÐMô × Ñ ×)Ñ)¨%°ÀÄÀUÃÐ1LÓMÐMr   c                óˆ   — |dk(  rt        | ||«      S |dk(  rt        ||«      S |dk(  rt        |«      S |j                  «       S )z2Decode the specified value given the fmt and type.r<   r7   r$   )rO   r]   r$   r   r=   s       r   Ú_decode_valuer_   Ð   sJ   € à�	ÒÜ˜r 3¨Ó.Ð.Ø	�&ŠÜ˜C Ó'Ð'Ø	�%ŠÜ�5‹zÐà�{‰{‹}Ðr   c                óˆ  — t        | «      } i }d}|r| j                  |«      r| t        |«      d } | �rt        j	                  | «      d   \  }}|r| j                  |«      s
t        «       ‚| t        |«      d } | dt        |d   «       }|r,|j                  d«      r| j                  |«      }|dkD  r| d| }| t        |«      d } |t        v r7t        t        |   t        «       t        «       dg«      }|j                  |«       t        ||d   |d   |«      ||<   |r| j                  |«      r| t        |«      d } | r�Œ|S )a`  Return a dictionary containing the information from the GS1-128 code.

    The returned dictionary maps application identifiers to values with the
    appropriate type (`str`, `int`, `Decimal`, `datetime.date` or
    `datetime.datetime`).

    If a `separator` is provided it will be used as FNC1 to determine the end
    of variable-sized values.
    r   Nr   ÚformatÚfnc1ÚvalidateÚtype)r   r    r&   Ú	_gs1_aidbÚinfoÚInvalidComponentrJ   ÚgetÚfindÚ_ai_validatorsÚ
__import__ÚglobalsÚlocalsrc   r_   )	r   Ú	separatorÚdataÚ
identifierr'   rf   r)   ÚidxÚmods	            r   rf   rf   Ü   sE  € ô �V‹_€FØ€DØ€Já�V×&Ñ& yÔ1Øœ˜I›˜Ð(ˆÚ
ä—>‘> &Ó)¨!Ñ,‰ˆˆDÙ˜6×,Ñ,¨RÔ0Ü"Ó$Ð$Øœ˜B›˜Ð!ˆàÐ3œ D¨¡NÓ3Ð4ˆÙ˜Ÿ™ &Ô)Ø—+‘+˜iÓ(ˆCØ�QŠwØ˜t ˜�Øœ˜E›
˜Ð$ˆà”ÑÜœ^¨BÑ/´³¼F»HÀzÀlÓSˆCØ�L‰L˜Ôä   T¨(¡^°T¸&±\À5ÓIˆˆR‰á˜×*Ñ*¨9Ô5ØœC 	›N˜OÐ,ˆFó+ ð, €Kr   c                óà  — |rdnd}g }g }t        | j                  «       «      D ]Ò  \  }}t        j                  t	        |«      «      d   \  }}	|	s
t        «       ‚|t        v r7t        t        |   t        «       t        «       dg«      }
|
j                  |«       t        ||	d   |	d   |«      \  }}|	j                  d«      s|j                  ||z  |z   «       Œµ|j                  ||z  |	d   |	d   |f«       ŒÔ dj                  ||d	d
 D ����cg c]  \  }}}}||r|nt        |||«      z   |z   ‘Œ  c}}}}z   |d
d	 D ����cg c]  \  }}}}||z   ‘Œ c}}}}z   «      S c c}}}}w c c}}}}w )a  Generate a GS1-128 for the application identifiers supplied.

    The provided dictionary is expected to map application identifiers to
    values. The supported value types and formats depend on the application
    identifier.

    If a `separator` is provided it will be used as FNC1 representation,
    otherwise variable-sized values will be expanded to their maximum size
    with appropriate padding.

    If `parentheses` is set the application identifiers will be surrounded
    by parentheses for readability.
    z(%s)z%sr   rc   ra   rd   rb   r   Nr   )ÚsortedÚitemsre   rf   r"   rg   rj   rk   rl   rm   rc   r?   rh   ÚappendÚjoinrM   )ro   rn   ÚparenthesesÚai_fmtÚfixed_valuesÚvariable_valuesÚinputair)   r'   rf   rr   r(   r>   s                r   Úencoder}     sŒ  € ñ #‰V¨€Fð €LØ€OÜ  §¡£Ó.ò W‰ˆ�Ü—>‘>¤# g£,Ó/°Ñ2‰ˆˆDÙÜ"Ó$Ð$à”ÑÜœ^¨BÑ/´³¼F»HÀzÀlÓSˆCØ�L‰L˜ÔÜ! " d¨8¡n°d¸6±lÀEÓJ‰	ˆˆEà�x‰x˜ÔØ×Ñ ¨¡¨eÑ 3Õ4à×"Ñ" F¨R¡K°°h±ÀÀfÁÈuÐ#UÕVðWð  �7‰7Øà)8¸¸"Ð)=÷
ñ 
á%��C˜ ð ™9‘%¬*°S¸%ÀÓ*GÑHÈ9ÓTõ
ñ 	
ð
 *9¸¸Ð)=÷
ñ 
á%��C˜ ð �‹Jõ
ñ	
óð ùõ
ùõ
s   Ä#E ÅE(c                óp   — 	 t        t        | |«      |«      S # t        $ r ‚ t        $ r t	        «       ‚w xY w)a  Check if the number provided is a valid GS1-128.

    This checks formatting of the number and values and returns a stable
    representation.

    If a separator is provided it will be used as FNC1 for both parsing the
    provided number and for encoding the returned number.
    )r}   rf   ÚValidationErrorÚ	ExceptionÚInvalidFormat©r   rn   s     r   rc   rc   2  s?   € ð	Ü”d˜6 9Ó-¨yÓ9Ð9øÜò ØÜò ô
 ‹oÐðús   ‚ ˜5c                óJ   — 	 t        t        | «      «      S # t        $ r Y yw xY w)z0Check if the number provided is a valid GS1-128.F)Úboolrc   r   r‚   s     r   Úis_validr…   G  s)   € ðÜ”H˜VÓ$Ó%Ð%øÜò Ùðús   ‚ –	"¡")r   r"   Úreturnr"   )r'   r"   r(   r"   r)   Úobjectr†   útuple[str, str])r(   r"   r)   r‡   r†   r"   )
r'   r"   r(   r"   r>   r"   r)   r‡   r†   rˆ   )r(   r"   r†   r$   )r(   r"   r>   r"   r)   r"   r†   r"   )r'   r"   r(   r"   r)   r"   r†   z-decimal.Decimal | tuple[str, decimal.Decimal])r(   r"   r)   r"   r†   zGdatetime.date | datetime.datetime | tuple[datetime.date, datetime.date])
r'   r"   r(   r"   r>   r"   r)   r"   r†   r   )r   )r   r"   rn   r"   r†   zdict[str, Any])r   F)ro   zMapping[str, object]rn   r"   rx   r„   r†   r"   )r   r"   rn   r"   r†   r"   )r   r"   rn   r"   r†   r„   ) Ú__doc__Ú
__future__r   r6   r<   rB   Ústdnumr   Ústdnum.exceptionsÚstdnum.utilr   ÚTYPE_CHECKINGÚcollections.abcr   Útypingr   rh   re   rj   r   r!   r5   r?   rJ   rM   rO   r]   r_   rf   r}   rc   r…   © r   r   ú<module>r’      s›   ðñ*õ: #ã Û Û 	å Ü Ý ð €ÙÝ'Ýð ˆE�I‰I�hÓ€	ð
 Ø
Øñ€ó'óTó4 óFóó-ó	"óNó(	ô&ôR*ôZõ*r   