
k4Vdc           @   s   d  Z  d f Z d d l m Z d d l m Z d d l m Z d e f d     YZ d   Z	 d   Z
 d	   Z d
   Z e d k r e   n  d S(   s   3.3.0t   USPS_4Statei(   t   black(   t   Barcode(   t   asNativec        D   B   s  e  Z d  Z d Z d Z d Z d Z e d dL d dM d
 dN d dO  Z e d dP d dQ d dR d
 dS  Z	 e d dT d dU d dV d dW  Z
 d d d  Z d   Z d   Z e e  Z d   Z e d   e  Z d    Z e d!   e  Z d"   Z e d#   e  Z d$   Z e d%   e  Z d&   Z e d'   e  Z d(   Z e d)   e  Z d*   Z e e  Z d+   Z e e  Z d,   Z e e  Z d-   Z e e  Z d.   Z e e  Z d/   Z e e  Z dX dY dZ d[ d\ d] d^ d_ d` da db dc dd de df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz d{ d| d} d~ d d d d d d d d d d d d d d d d d d d d d d d d d d fA Z d Z e d:    Z e d;    Z e d<    Z  e d=    Z! e d>    Z" e d?    Z# e d@    Z$ dA   Z% e e%  Z% dB   Z& e e&  Z& dC   Z' dD   Z( d dE  Z) dF   Z* dG   Z+ e e+ dH    Z+ dI   Z, dJ dK  Z- RS(   sC    USPS 4-State OneView (TM) barcode. All info from USPS-B-3200A
    i   i   i    t   Fgx&?gq=
ףp?t   Tg/$?g{Gz?t   At   Dgx&gq=
ףpg/$g{Gzt   widthgQ?g?t   pitchg_L?g?t   hczg      ?t   vczt   01234567094987654321t    c         K   sT   |  j    t | t  r% t |  n	 t |  } | |  _ | |  _ |  j |   d  S(   N(   t   _initt
   isinstancet   intt   strR   t	   _trackingt   _routingt   _setKeywords(   t   selft   valuet   routingt   kwd(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   __init__$   s
    
'		c         C   s(   d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   t   Nonet   _bvaluet
   _codewordst   _characterst	   _barcodes(   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR   +   s    			c         C   s*   | |  } d | d d | | | d S(   NiH   i    i   (    (   t   kindR   t   st   V(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   scale1   s    
c         C   s   |  j    | |  _ d  S(   N(   R   R   (   R   t   tracking(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR#   6   s    
c         C   s   |  j  S(   N(   R   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   <lambda>9   R   c         C   s   |  j    | |  _ d  S(   N(   R   R   (   R   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR   ;   s    
c         C   s   |  j  S(   N(   R   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$   >   R   c         C   s   d  |  _ | |  _ d  S(   N(   R   t   _sizedt
   _widthSize(   R   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt	   widthSize@   s    	c         C   s   |  j  S(   N(   R&   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$   C   R   c         C   s   d  |  _ | |  _ d  S(   N(   R   R%   t   _heightSize(   R   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt
   heightSizeE   s    	c         C   s   |  j  S(   N(   R(   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$   H   R   c         C   s   d  |  _ | |  _ d  S(   N(   R   R%   t	   _fontSize(   R   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   fontSizeJ   s    	c         C   s   |  j  S(   N(   R*   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$   M   R   c         C   s   d  |  _ | |  _ d  S(   N(   R   R%   t   _humanReadable(   R   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   humanReadableO   s    	c         C   s   |  j  S(   N(   R,   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$   R   R   c   
      C   s  |  j  } | s|  j } t |  } y| | d k r< d } nc | d k r[ t |  d } nD | d k rz t |  d } n% | d k r t |  d } n t  Wn t d |   n X|  j } | d d	 !} y@ | d
 9} | t | d  7} | d 9} | t | d  7} Wn t d |   n Xd	 } x d d d f D] \ } } | }	 | | 7} | |	 | !} yT t |  | k rt  n  x2 t |  D]$ }	 | d
 9} | t | |	  7} qWWq@t d | | | f   q@Xq@W| |  _  n  | S(   s  convert the 4 state string values to binary
        >>> print hex(USPS_4State('01234567094987654321','').binary)
        0x1122103B5C2004B1L
        >>> print hex(USPS_4State('01234567094987654321','01234').binary)
        0xD138A87BAB5CF3804B1L
        >>> print hex(USPS_4State('01234567094987654321','012345678').binary)
        0x202BDC097711204D21804B1L
        >>> print hex(USPS_4State('01234567094987654321','01234567891').binary)
        0x16907B2A24ABC16A2E5C004B1L
        i    i   i   i	   i i   iP;s@   Problem converting %s, routing code must be 0, 5, 9 or 11 digitsi   i
   s:   Problem converting %s, barcode identifier must be 2 digitss   special servicesi   s   customer identifieri   s   sequence numbers+   Problem converting %s, %s must be %d digits(   s   special servicesi   (   s   customer identifieri   (   s   sequence numberi	   (   R   R   t   lenR   t
   ValueErrorR#   t   range(
   R   R   R   t   nR#   t   svaluet   it   namet   ndt   j(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   binaryT   sP    			
	


 	
!c         C   s  |  j  sy|  j } t | d  \ } } t | d  \ } } t | d  \ } } t | d  \ } } t | d  \ } } t | d  \ } } t | d  \ } }	 t | d  \ } }
 t | d  \ } } d | k o d k n st d t t |   | f   t |  |  _ |  j d @r6| d 7} n  | d 9} t t	 t | | |
 |	 | | | | | | f
   |  _  n  |  j  S(	   s   convert binary value into codewords
        >>> print USPS_4State('01234567094987654321','01234567891').codewords)
        (673, 787, 607, 1022, 861, 19, 816, 1294, 35, 602)
        i|  iU  i    i  s.   improper value %s passed to _2codewords A-->%si   i  i   (
   R   R7   t   divmodt   AssertionErrort   hexR   t   _crc11t   _fcst   tuplet   map(   R   R   R   t   Jt   It   Ht   GR   t   ER   t   Ct   B(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt	   codewords   s$    		> 
9c         C   s   t  d d  |  j _ |  j j S(   Ni   i  (   t   _initNof13Tablet	   __class__t   table1(   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyRI      s    c         C   s   t  d d  |  j _ |  j j S(   Ni   iN   (   RG   RH   t   table2(   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyRJ      s    c   
      C   s   |  j  s |  j } |  j } g  } | j } |  j } |  j } xk t d  D]] } | | } | d k rr | | }	 n | | d }	 | | ?d @r |	 d @}	 n  | |	  qI Wt |  |  _  n  |  j  S(   s    convert own codewords to characters
        >>> print ' '.join(hex(c)[2:] for c in USPS_4State('01234567094987654321','01234567891').characters)
        dcb 85c 8e4 b06 6dd 1740 17c6 1200 123f 1b2b
        i
   i  i  i   i  (   R   RF   R<   t   appendRI   RJ   R0   R=   (
   R   RF   t   fcsRD   t   aCRI   RJ   R3   t   cwt   c(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt
   characters   s"    						
c   	      C   s   |  j  s |  j } g  } | j } |  j } xK |  j D]@ \ } } } } | | | | | ?d @d | | | ?d @ q4 Wd j |  |  _  n  |  j  S(   s   Get 4 state bar codes for current routing and tracking
        >>> print USPS_4State('01234567094987654321','01234567891').barcodes
        AADTFFDFTDADTAADAATFDTDDAAADDTDTTDAFADADDDTFFFDDTTTADFAAADFTDAADA
        i   i   R   (   R   RP   RK   t
   _bits2barst   table4t   join(	   R   RD   RE   t   aBt	   bits2barst   dct   dbt   act   ab(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   barcodes   s    				2i   i   i   i   i
   i	   i   i   i   i   c         C   s   |  j  d |  j |  j  S(   NR
   (   R"   t
   dimensionst
   widthScale(   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$      R   c         C   s   |  j  d |  j |  j  S(   NR   (   R"   R[   t   heightScale(   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$      R   c         C   s   |  j  d |  j |  j  S(   NR	   (   R"   R[   R\   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$      R   c         C   s   |  j  d |  j |  j  S(   NR   (   R"   R[   R\   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$      R   c         C   s2   |  j  d |  j |  j  |  j  d |  j |  j  S(   NR   (   R"   t   topsR]   t   bottoms(   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$      R   c         C   s   t  d t d |  j   S(   Ni   i    (   t   mint   maxR'   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$      R   c         C   s   t  d t d |  j   S(   Ni   i    (   R`   Ra   R)   (   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$      R   c         C   s   |  j    |  j S(   N(   t   computeSizet   _width(   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR      s    
c         C   s   |  j    |  j S(   N(   Rb   t   _height(   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   height   s    
c         C   s   t  |  d d   s |  j } |  j } |  j } |  j } |  j } |  j } |  j } d | | d | |  _	 d | | |  _
 |  j r |  j
 |  j d | 7_
 n  t |  _ n  d  S(   NR%   i   i@   g333333?(   t   getattrR   R\   R]   t	   barHeightt   barWidthR	   t   horizontalClearZonet   verticalClearZoneRc   Rd   R-   R+   t   TrueR%   (   R   t   wst   hsRg   Rh   R	   R
   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyRb      s    								c         C   s   |  j    |  j |  j f S(   N(   Rb   R   Re   (   R   t   aWt   aH(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   wrap  s    
c         C   sj   i  } |  j  } xT d D]L } |  j | |  j |  | } | |  j | |  j |  | | f | | <q W| S(   NR   R   R   R   (   R   R   R   R   (   R]   R"   R_   R^   (   R   t   y0t   vInfoRm   t   bt   y(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   _getBarVInfo  s    	.c         C   s   |  j    |  j } |  j } |  j } | } | |  j d } |  j } |  j |  } xA |  j D]6 } | | \ }	 }
 |  j | |	 | |
  | | 7} q^ W|  j	   d  S(   Ng      ?(
   Rb   Ri   Rj   Rh   Rg   R	   Ru   RZ   t   rectt   drawHumanReadable(   R   R
   R   t   bwt   xRq   t   dwRr   Rs   t   ybt   hb(    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   draw  s    
				c         C   s]   |  j  } |  j } | r! | f p$ d } d j | d d !| d d !| d d !| d f |  S(   Nt    i    i   i   i   (    (   R#   R   RS   (   R   R#   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR   &  s    		c         C   s   |  j  j d |  S(   NR#   (   t   __dict__t   __setitem__(   R   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR$   +  R   c         C   si   |  j  re |  j } |  j } |  j } |  j } |  j d | d | } |  j | | |  j | |  n  d  S(   Ni   g?(   R-   Ri   Rj   t   fontNameR+   Rg   t   annotateR   (   R   R
   R   R   R+   Rt   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyRw   -  s    					t   middlec      	   C   s&   t  j |  | | | | | d d d  S(   Nt   anchort   start(   R   R   (   R   Ry   Rt   t   textR   R+   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR   6  s    (   gx&?gq=
ףp?(   g/$?g{Gz?(   gx&?gq=
ףp?(   g/$?g{Gz?(   gx&gq=
ףp(   gx&gq=
ףp(   g/$g{Gz(   g/$g{Gz(   gQ?g?(   g_L?g?(   g      ?g      ?(   g{Gz?g{Gz?(   i   i   i   i   (   i   i
   i    i    (   i	   i   i   i   (   i   i   i   i   (   i   i	   i   i   (   i    i   i   i   (   i   i   i   i   (   i   i   i	   i   (   i   i   i   i
   (   i   i	   i   i   (   i   i   i   i   (   i   i   i   i   (   i	   i
   i    i   (   i   i   i   i   (   i   i   i   i	   (   i    i   i   i   (   i   i   i   i   (   i   i   i	   i	   (   i   i
   i   i   (   i   i    i   i   (   i   i   i    i   (   i   i   i   i    (   i	   i   i   i   (   i   i   i   i   (   i   i   i   i
   (   i   i   i   i	   (   i   i   i   i    (   i   i   i	   i   (   i   i   i   i
   (   i   i   i    i   (   i   i   i   i   (   i   i   i   i	   (   i   i    i	   i   (   i    i   i   i   (   i   i   i   i   (   i   i	   i   i   (   i   i   i   i   (   i	   i   i   i   (   i   i   i   i   (   i    i   i   i    (   i   i   i   i   (   i   i
   i   i   (   i   i   i	   i   (   i   i   i   i   (   i    i   i   i   (   i   i   i   i   (   i   i
   i   i    (   i	   i   i    i	   (   i   i   i   i   (   i   i   i   i   (   i   i    i   i   (   i   i   i    i
   (   i   i   i	   i   (   i   i   i   i   (   i   i   i   i	   (   i   i   i    i   (   i   i   i   i   (   i	   i   i   i   (   i   i   i   i   (   i   i    i   i   (   i   i   i   i   (   i    i   i   i   (   i   i	   i	   i    (   i   i   i   i   (   i   i
   i   i   (   R   R   R   R   (.   t   __name__t
   __module__t   __doc__R&   R(   R*   R,   t   dictR^   R_   R[   R   R   R"   t   staticmethodR#   t   propertyR   R'   R)   R+   R-   R7   RF   RI   RJ   RP   RZ   RR   RQ   Ri   Rj   R	   Rh   Rg   R\   R]   R   Re   Rb   Rp   Ru   R}   R   Rw   R   (    (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR    
   s   												5														c         C   s>  t  t |    d d !} d d t |  | } d } d } t | d  d  d >} xT t d d	  D]C } | | Ad
 @r | d >| A} n
 | d >} | d M} | d K} qd Wx t d d d  D]x } t | | | d !d  d >} xQ t d	  D]C } | | Ad
 @r| d >| A} n
 | d >} | d M} | d K} q Wq W| S(   s   
    >>> print ' '.join(hex(_crc11(USPS_4State('01234567094987654321',x).binary)) for x in ('','01234','012345678','01234567891'))
    0x51 0x65 0x606 0x751
    i   it   0i   i5  i  i   i   i   i   i   i   i   i   (   R:   R   R.   R0   (   R   t   bytest   gpRL   t   dataRs   Ry   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyR;   9  s(    



c         C   sC   d } x6 t  d  D]( } | d K} | |  d @O} |  d L}  q W| S(   st   reverse unsigned 13 bit number
    >>> print _ru13(7936), _ru13(31), _ru13(47), _ru13(7808)
    31 7936 7808 47
    i    i   i   (   R0   (   R3   t   rRy   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   _ru13V  s    
c   	      C   s  | d g } d } | d } x t d  D] } d } x, t d  D] } | | d | >@d k 7} qC W| |  k rw q* n  t |  } | | k  r q* n  | | k r | | | <| d 8} q* | | | <| d 7} | | | <| d 7} q* W| | d k st d | d | |  f   | S(   s+  create and return table of 13 bit values with N bits on
    >>> T = _initNof13Table(5,1287)
    >>> print ' '.join('T[%d]=%d' % (i, T[i]) for i in (0,1,2,3,4,1271,1272,1284,1285,1286))
    T[0]=31 T[1]=7936 T[2]=47 T[3]=7808 T[4]=55 T[1271]=6275 T[1272]=6211 T[1284]=856 T[1285]=744 T[1286]=496
    i    i   i    i   s!   u+1(%d)!=l(%d) for %d of 13 tableN(   R   R0   R   R9   (	   t   Nt   lenTR   t   lt   uRO   t   bcRs   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyRG   b  s*    
  



-c          C   s   d d  l  }  |  j   S(   Ni(   t   doctestt   testmod(   R   (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   _test}  s    t   __main__N(   t   __version__t   __all__t   reportlab.lib.colorsR   t!   reportlab.graphics.barcode.commonR   t   reportlab.lib.utilsR   R    R;   R   RG   R   R   (    (    (    so   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/reportlab/graphics/barcode/usps4s.pyt   <module>   s   	 0				