PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/pypy/module/binascii/interp_crc32.py

https://bitbucket.org/pypy/pypy/
Python | 12 lines | 10 code | 2 blank | 0 comment | 0 complexity | b383b83724d161fa21144d2cb6b89e01 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  1. from pypy.interpreter.gateway import unwrap_spec
  2. from rpython.rtyper.lltypesystem import rffi
  3. from rpython.rlib.rarithmetic import r_uint, intmask
  4. from rpython.rlib import rzipfile
  5. @unwrap_spec(data='bufferstr', oldcrc='truncatedint_w')
  6. def crc32(space, data, oldcrc=0):
  7. "Compute the CRC-32 incrementally."
  8. crc = rzipfile.crc32(data, r_uint(oldcrc))
  9. crc = rffi.cast(rffi.INT, crc) # unsigned => 32-bit signed
  10. return space.wrap(intmask(crc))