³ò
8GIc           @   sÞ  d  Z  d i ƒ  Z y d d k Z e Z Wn% e j
 o d d k Z e	 Z n Xd d k
 Z
 d d k Z d d d „  ƒ  YZ d e d „ Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z h  e i e i g d <e i e i g d <e i e i g d <e i e i g d <e i e i g d <Z h  Z x d i ƒ  D]q Z  h  d d <d d <d d <d d <i! e i" e  ƒ d ƒ Z$ e$ d j	 o e$ e j o d e  e e$ <qBqBWe d e d <[  [$ d „  Z% d Z& d S(   sl  crcmod is a Python module for gererating objects that compute the Cyclic
Redundancy Check.  Any 8, 16, 24, 32, or 64 bit polynomial can be used.  

The following are the public components of this module.

Crc -- a class that creates instances providing the same interface as the
md5 and sha modules in the Python standard library.  These instances also
provide a method for generating a C/C++ function to compute the CRC.

mkCrcFun -- create a Python function to compute the CRC using the specified
polynomial and initial value.  This provides a much simpler interface if
all you need is a function for CRC calculation.
s   mkCrcFun Crc
iÿÿÿÿNt   Crcc           B   sh   e  Z d  Z d
 e e d „ Z d „  Z d d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d d d	 „ Z RS(   s†  Compute a Cyclic Redundancy Check (CRC) using the specified polynomial.

    Instances of this class have the same interface as the md5 and sha modules
    in the Python standard library.  See the documentation for these modules
    for examples of how to use a Crc instance.

    The string representation of a Crc instance identifies the polynomial and
    the initial and current CRC values.  The print statement can be used to
    output this information.

    If you need to generate a C/C++ function for use in another application,
    use the generateCode method.  If you need to generate code for another
    language, subclass Crc and override the generateCode method.

    The following are the parameters supplied to the constructor.

    poly -- The generator polynomial to use in calculating the CRC.  The value
    is specified as a Python integer or long integer.  The bits in this integer
    are the coefficients of the polynomial.  The only polynomials allowed are
    those that generate 8, 16, 24, 32, or 64 bit CRCs.

    initCrc -- Initial value used to start the CRC calculation.  Defaults to
    all bits set because that starting value will take leading zero bytes into
    account.  Starting with zero will ignore all leading zero bytes.

    rev -- A flag that selects a bit reversed algorithm when True.  Defaults to
    True because the bit reversed algorithms are more efficient.
    l    c         C   s{   | p d  Sn t  | | | ƒ } | d |  _ | d d |  _ | d |  _ | d |  _ |  i |  _ | |  _ | |  _ d  S(   Ni    i   i   i   i   (   t	   _mkCrcFunt   _crct   digest_sizet   initCrct   tablet   crcValuet   reverset   poly(   t   selfR   R   t   revt
   initializet   x(    (    s    /root/databuoy/scripts/crcmod.pyt   __init__Q   s    	c         C   s|   g  } | i  d |  i ƒ | i  d |  i ƒ d |  i d } | i  d | |  i ƒ | i  d | |  i ƒ d i | ƒ S(   Ns   poly = 0x%Xs   reverse = %ss   0x%%0%dXi   s   initCrc  = %ss   crcValue = %ss   
(   t   appendR   R   R   R   R   t   join(   R	   t   lstt   fmt(    (    s    /root/databuoy/scripts/crcmod.pyt   __str__`   s    c         C   s‹   t  d d d t ƒ } |  i | _ |  i | _ |  i | _ |  i | _ |  i | _ |  i | _ |  i	 | _	 | d j	 o | i
 | ƒ n | S(   s	  Create a new instance of the Crc class initialized to the same
        values as the original instance.  The current CRC is set to the initial
        value.  If a string is provided in the optional arg parameter, it is
        passed to the update method.
        R   R   N(   R    t   Nonet   FalseR   R   R   R   R   R   R   t   update(   R	   t   argt   n(    (    s    /root/databuoy/scripts/crcmod.pyt   newi   s    c         C   s   |  i  ƒ  } |  i | _ | S(   sô   Create a new instance of the Crc class initialized to the same
        values as the original instance.  The current CRC is set to the current
        value.  This allows multiple CRC calculations using a common initial
        string.
        (   R   R   (   R	   t   c(    (    s    /root/databuoy/scripts/crcmod.pyt   copy{   s    c         C   s   |  i  | |  i ƒ |  _ d S(   s_   Update the current CRC value using the string specified as the data
        parameter.
        N(   R   R   (   R	   t   data(    (    s    /root/databuoy/scripts/crcmod.pyR   …   s    c         C   so   |  i  } |  i } g  } x= | d j o/ | i t | d @ƒ ƒ | d ?} | d 8} q W| i ƒ  d i | ƒ S(   s‰   Return the current CRC value as a string of bytes.  The length of
        this string is specified in the digest_size attribute.
        i    iÿ   i   i   t    (   R   R   R   t   chrR   R   (   R	   R   t   crcR   (    (    s    /root/databuoy/scripts/crcmod.pyt   digest‹   s    		 

c         C   sm   |  i  } |  i } g  } x; | d j o- | i d | d @ƒ | d ?} | d 8} q W| i ƒ  d i | ƒ S(   s‡   Return the current CRC value as a string of hex digits.  The length
        of this string is twice the digest_size attribute.
        i    s   %02Xiÿ   i   i   R   (   R   R   R   R   R   (   R	   R   R   R   (    (    s    /root/databuoy/scripts/crcmod.pyt	   hexdigest™   s    		 

c         C   s:  | d j o
 d } n | d j o2 d |  i } | d j o
 d } n d | } n |  i d j o
 d } n0 |  i o
 d } n d |  i d } d	 | } d
 d |  i } |  i d j o | d } n | d } h  d d <d d <d d <d d <d d <|  i }	 g  }
 xP t |  i ƒ D]? \ } } | |	 d j o |
 i d ƒ n |
 i | | ƒ q(Wd |  i } |  i o | d } n d } d } |  i d j o |  i o
 d } qÊd } n h  | d <| d <| d <| | d <d i |
 ƒ d <| d <| d <| d <} | i t	 | ƒ d S(   s(  Generate a C/C++ function.

        functionName -- String specifying the name of the function.

        out -- An open file-like object with a write method.  This specifies
        where the generated code is written.

        dataType -- An optional parameter specifying the data type of the input
        data to the function.  Defaults to UINT8.

        crcType -- An optional parameter specifying the data type of the CRC
        value.  Defaults to one of UINT8, UINT16, UINT32, or UINT64 depending
        on the size of the CRC value.
        t   UINT8i   i   i    s   UINT%di   s   table[*data ^ (%s)crc]s#   table[*data ^ (%s)crc] ^ (crc >> 8)s,   table[*data ^ (%%s)(crc >> %d)] ^ (crc << 8)s   0x%%0%dXi   i   s   U,s   ULL,i   i    s   
    s   polynomial: 0x%Xs   , bit reverse algorithmR   s   
    crc = crc & 0xFFFFFFU;t   dataTypet   crcTypet   namet   crcAlgort   crcTableR   t   preConditiont   postConditionN(
   R   R   R   t	   enumerateR   R   R   R   t   writet   _codeTemplate(   R	   t   functionNamet   outR"   R#   t   sizeR%   t   shiftR   R   R   t   it   valR   R'   R(   t   parms(    (    s    /root/databuoy/scripts/crcmod.pyt   generateCode§   sV    






: 



					lÿÿÿÿ N(   t   __name__t
   __module__t   __doc__t   TrueR   R   R   R   R   R   R   R    R3   (    (    (    s    /root/databuoy/scripts/crcmod.pyR    4   s   			
			l    c         C   s   t  |  | | ƒ d S(   s]  Return a function that computes the CRC using the specified polynomial.

    poly -- integer representation of the generator polynomial
    initCrc -- default initial CRC value
    rev -- when true, indicates that the data is processed bit reversed.

    The returned function has the following user interface
    def crcfun(data, crc=initCrc):
    i    (   R   (   R   R   R
   (    (    s    /root/databuoy/scripts/crcmod.pyt   mkCrcFunø   s    c         C   sm   d } t  |  ƒ }  xH d	 D]@ } d | >} | d } | |  j o
 | j  n o | Sq q Wt | ƒ ‚ d  S(
   Ns8   The degree of the polynomial must be 8, 16, 24, 32 or 64i   i   i   i    i@   l    i   (   i   i   i   i    i@   (   t   longt
   ValueError(   R   t   msgR   t   lowt   high(    (    s    /root/databuoy/scripts/crcmod.pyt   _verifyPoly  s     

c         C   so   t  |  ƒ }  d } x0 t | ƒ D]" } | d >|  d @B} |  d ?}  q Wd | >d t i j o t | ƒ Sn | S(   Nl    i   l    (   R9   t   xranget   syst   maxintt   int(   R   R   t   yR0   (    (    s    /root/databuoy/scripts/crcmod.pyt   _bitrev  s     c         C   sž   t  |  ƒ }  t  | ƒ } d | d >} x; t d ƒ D]- } |  | @o |  d >| A}  q3 |  d >}  q3 Wd | >d } |  | @}  | t i j o t |  ƒ Sn |  S(   Nl    i   i   (   R9   R?   R@   RA   RB   (   R   R   R   t   maskR0   (    (    s    /root/databuoy/scripts/crcmod.pyt   _bytecrc*  s     
c         C   s   t  |  ƒ }  t  | ƒ } x; t d ƒ D]- } |  d @o |  d ?| A}  q% |  d ?}  q% Wd | >d } |  | @}  | t i j o t |  ƒ Sn |  S(   Ni   l    i   (   R9   R?   R@   RA   RB   (   R   R   R   R0   RE   (    (    s    /root/databuoy/scripts/crcmod.pyt
   _bytecrc_r9  s     
c         C   sc   d | >d } t  |  ƒ | @}  g  } t d ƒ D]' } | t t  | ƒ | d >|  | ƒ q/ ~ } | S(   Nl    i   i   i   (   R9   R?   RF   (   R   R   RE   t   _[1]R0   R   (    (    s    /root/databuoy/scripts/crcmod.pyt   _mkTableO  s    Ac         C   sd   d | >d } t  t |  ƒ | @| ƒ }  g  } t d ƒ D] } | t t | ƒ |  | ƒ q8 ~ } | S(   Nl    i   i   (   RD   R9   R?   RG   (   R   R   RE   RH   R0   R   (    (    s    /root/databuoy/scripts/crcmod.pyt
   _mkTable_rU  s    9i   i   i   i    i@   s	   B H I L Qi   i   i   s   256%sc   	      C   sØ   t  |  ƒ } d | >d } t | ƒ | @} | t i j o t | ƒ } n | o! t |  | ƒ } t | d } n t |  | ƒ } t | d } | } t o t	 i
 t | | Œ } n | | | d „ } | | | | f S(   Nl    i   i    c         S   s   | |  | | ƒ S(   N(    (   R   R   R   t   fun(    (    s    /root/databuoy/scripts/crcmod.pyt   crcfun’  s    (   R>   R9   R@   RA   RB   RJ   t   _sizeMapRI   t   _usingExtensiont   structt   packt   _sizeToTypeCode(	   R   R   R
   R.   RE   t	   tableListt   _funt   _tableRL   (    (    s    /root/databuoy/scripts/crcmod.pyR   ~  s    sK  // Automatically generated CRC function
// %(poly)s
%(crcType)s
%(name)s(%(dataType)s *data, int len, %(crcType)s crc)
{
    static const %(crcType)s table[256] = {%(crcTable)s
    };
    %(preCondition)s
    while (len > 0)
    {
        crc = %(crcAlgor)s;
        data++;
        len--;
    }%(postCondition)s
    return crc;
}
(    lÿÿÿÿ ('   R6   t   splitt   __all__t
   _crcfunextt   _crcfunR7   RN   t   ImportErrort	   _crcfunpyR   R@   RO   R    R8   R>   RD   RF   RG   RI   RJ   t   _crc8t   _crc8rt   _crc16t   _crc16rt   _crc24t   _crc24rt   _crc32t   _crc32rt   _crc64t   _crc64rRM   RQ   t   typeCodet   gett   calcsizeR   R.   R   R+   (    (    (    s    /root/databuoy/scripts/crcmod.pys   <module>"   s@   
Ä								 ?		*