From: Thomas P. <te...@gm...> - 2007-12-10 04:55:04
|
On Saturday 08 December 2007, Jesus Cea wrote: > I was thinking about installing "pycrc" and be able to do "from pycrc > import crc_32" without needing to generate and compile the C module > myself :). So pycrc would be both a code to create C libs and a python C > lib itself. Hi Jesus, I have been playing around with C modules this week-end, and I'm not quite there but I think it is in a stage where I can show it around. I have put some code to the temporary URL: http://www.tty1.net/tmp/pycrc-0.7.test1.zip http://www.tty1.net/tmp/pycrc-0.7.test1.tar.gz in the module directory you will find code for a generic (slow) Crc implementation and a CRC32 (table-driven) model. It would be very helpful if you could give me some early feedback on the code. This is the first time for me I tinker with python/C interface so it is very likely I got something wrong. At the moment the instructions (and maybe also the code) are quite UNIX orientated, so please tell me if you have problems under Windows. You can compile the lib with: python setup.py build and if you copy the .so file into the local directory, where you have a script like the one at the end of the mail. Any feedback is greatly welcome. Cheers, Thomas #!/usr/bin/env python from pycrc import PyCrc, PyCrc32 import sys def main(): crc = PyCrc(width = 32, poly = 0x04c11db7L, reflect_in = True, xor_in = 0xffffffffL, reflect_out = True, xor_out = 0xffffffffL) # crc = PyCrc(16, 0x8005L, True, 0x0L, True, 0x0L) # crc = PyCrc32() for x in "123456789": crc.update(x) crc.finalize() print "0x%x" % crc.value() return 0 if __name__ == "__main__": sys.exit(main()) |