
    Q?h                         S SK Jr  S SKJr  S SKJrJr  S SK	J
r
  SSSSS	.rS
SSSSSSSSSSS.r " S S\5      r " S S\5      rg)    )inch)Barcode)digits
whitespace)asNativez	||  |  ||z	| || || |z	|| | | ||z	||| | |||)ABCDz...||z..|.|z..||.z.|..|z.|.|.z.||..z|...|z|..|.z|.|..z||...|)1234567890Sc                   v    \ rS rSrSr\S-  r\S-  r\S-  r\S-  r	\S-  r
SrSS	 jrS
 rS rS rS rS rSrg)FIM6   a!  
FIM (Facing ID Marks) encode only one letter.
There are currently four defined:

A   Courtesy reply mail with pre-printed POSTNET
B   Business reply mail without pre-printed POSTNET
C   Business reply mail with pre-printed POSTNET
D   OCR Readable mail without pre-printed POSTNET

Options that may be passed to constructor:

    value (single character string from the set A - D. required.):
        The value to encode.

    quiet (bool, default 0):
        Whether to include quiet zones in the symbol.

The following may also be passed, but doing so will generate nonstandard
symbols which should not be used. This is mainly documented here to
show the defaults:

    barHeight (float, default 5/8 inch):
        Height of the code. This might legitimately be overriden to make
        a taller symbol that will 'bleed' off the edge of the paper,
        leaving 5/8 inch remaining.

    lquiet (float, default 1/4 inch):
        Quiet zone size to left of code, if quiet is true.
        Default is the greater of .25 inch, or .15 times the symbol's
        length.

    rquiet (float, default 15/32 inch):
        Quiet zone size to right left of code, if quiet is true.

Sources of information on FIM:

USPS Publication 25, A Guide to Business Mail Preparation
http://new.usps.com/cpim/ftp/pubs/pub25.pdf
g      ?g      ?g      ?g      ?g      ?r   c                     [        U[        5      (       a  [        U5      O
[        U5      nUR	                  5        H  u  p4[        XU5        M     [        R                  " X5        g N
isinstanceintstrr   itemssetattrr   __init__selfvalueargskvs        Q/var/www/html/env/lib/python3.13/site-packages/reportlab/graphics/barcode/usps.pyr#   FIM.__init__d   I    (s33E
%JJLDADQ ! 	%    c                    SU l         SU l        U R                   H@  nU[        ;   a  M  US;   a$  U R                  UR	                  5       -   U l        M9  SU l         MB     [        U R                  5      S:w  a  [        S5      eU R                  $ )N    abcdABCDr   z#Input must be exactly one character)valid	validatedr&   string_whitespaceupperlen
ValueErrorr%   cs     r*   validateFIM.validatek   sw    
A%%j!%!'')!;
  t~~!#BCC~~r-   c                     SU l         U R                   H  nU R                   [        U   -   U l         M      U R                   $ Nr0   )
decomposedencoded_fim_patternsr8   s     r*   	decomposeFIM.decompose{   s8    A"ooa0@@DO  r-   c                    [        U R                  5      S-
  U R                  -  U R                  -   U l        U R
                  (       a,  U =R                  U R                  U R                  -   -  sl        U R                  U l	        g Nr/   )
r6   r>   
spaceWidthbarWidth_widthquietlquietrquiet	barHeight_heightr%   s    r*   computeSizeFIM.computeSize   sV    4??+a/4??BT]]R::KK4;;44K~~r-   c                 2   U R                  5         U R                  =(       a    U R                  =(       d    SnU R                   H?  nUS:X  a(  U R	                  USU R
                  U R                  5        XR                  -  nMA     U R                  5         g )Nr   r           )	
_calculaterH   rI   r>   rectrF   rK   rE   drawHumanReadable)r%   leftr9   s      r*   drawFIM.draw   sl    zz)dkk.QACx		$T]]DNNCOO#D ! 	 r-   c                     U R                   $ r   )r&   rM   s    r*   
_humanTextFIM._humanText   s    zzr-   )rL   rG   r>   r2   r3   Nr0   )__name__
__module____qualname____firstlineno____doc__r   rF   rE   rK   rJ   rI   rH   r#   r:   rA   rN   rV   rY   __static_attributes__ r-   r*   r   r   6   s^    &N x H"J IT]FYFE& &!r-   r   c                   r    \ rS rSrSrSr\S-  r\S-  r\S-  r	\S-  r
SS jrS	 rS
 rS rS rS rS rSrg)POSTNET   ai  
POSTNET is used in the US to encode "zip codes" (postal codes) on
mail. It can encode 5, 9, or 11 digit codes. I've read that it's
pointless to do 5 digits, since USPS will just have to re-print
them with 9 or 11 digits.

Sources of information on POSTNET:

USPS Publication 25, A Guide to Business Mail Preparation
http://new.usps.com/cpim/ftp/pubs/pub25.pdf
r   g?g      ?g;On?g)\(?c                     [        U[        5      (       a  [        U5      O
[        U5      nUR	                  5        H  u  p4[        XU5        M     [        R                  " X5        g r   r   r$   s        r*   r#   POSTNET.__init__   r,   r-   c                 J   SU l         SU l        SnU R                   HX  nU[        S-   ;   a  M  U[        ;   a5  US-   nUS:X  a  U R                   S-   U l         U R                   U-   U l         MQ  SU l        MZ     [        U R                   5      S;  a  SU l        U R                   $ )Nr0   r/   r   -   )   
      )r3   r2   r&   r4   string_digitsr6   )r%   countr9   s      r*   r:   POSTNET.validate   s    
A&,-m#	A:%)^^c%9DN!%!!3
  t~~k1DJ~~r-   c                     SU l         SnU R                   HB  nU[        ;   a$  U R                   U-   U l         U[        U5      -   nM1  US:X  a  M9  [	        S5      e   SU-
  S-  nU R                   [        U5      -   S-   U l         U R                   $ )Nr   r   ri   zInvalid character in inputrl   )r?   r3   rn   r   r7   repr)r%   checkr9   s      r*   encodePOSTNET.encode   s    AM!#||a/Ac !=>>   er!||d5k1C7||r-   c                     SU l         U R                   H  nU R                   [        U   -   U l         M      U R                   $ r=   )r>   r?   _postnet_patternsr8   s     r*   rA   POSTNET.decompose   s7    A"oo0A!0DDDO r-   c                     [        U R                  5      U R                  -  [        U R                  5      S-
  U R                  -  -   U l        U R
                  U l        g rD   )r6   r>   rF   rE   rG   rK   rL   rM   s    r*   rN   POSTNET.computeSize   sF    $//*T]]:c$//>RUV>VZ^ZiZi=ii~~r-   c                 P   U R                  5         U R                  U R                  -
  nSnU R                   H[  nUS:X  a  U R                  nOU R                  nU R	                  USU R
                  U5        X R
                  -   U R                  -   nM]     U R                  5         g )Nr   .rQ   )rR   rK   shortHeightr>   rS   rF   rE   rT   )r%   sdownrU   r9   hs        r*   rV   POSTNET.draw   s    !1!11ACx$$NNIIdC2--'$//9D ! 	 r-   c                      U R                   SS $ )Nr/   )r?   rM   s    r*   rY   POSTNET._humanText   s    ||Ab!!r-   )rL   rG   r>   r?   r2   r3   Nr[   )r\   r]   r^   r_   r`   rH   r   r}   rK   rF   rE   r#   r:   rt   rA   rN   rV   rY   ra   rb   r-   r*   rd   rd      sU    
 E,KuIe|HJ&(&!"r-   rd   N)reportlab.lib.unitsr   !reportlab.graphics.barcode.commonr   stringr   rn   r   r4   reportlab.lib.utilsr   r@   rw   r   rd   rb   r-   r*   <module>r      si   B % 5 K ( 


	 Gg
Gg
Gc \' \|T"g T"r-   