would expect.
Fixes issues1202.
the algorithm is designed for use as a checksum algorithm, it is not suitable
for use as a general hash algorithm.
+ Always returns an unsigned 32-bit integer.
+
.. function:: compress(string[, level])
the algorithm is designed for use as a checksum algorithm, it is not suitable
for use as a general hash algorithm.
+ Always returns an unsigned 32-bit integer.
+
.. function:: decompress(string[, wbits[, bufsize]])
self.assertEqual(zlib.crc32(b"penguin"), zlib.crc32(b"penguin", 0))
self.assertEqual(zlib.adler32(b"penguin"),zlib.adler32(b"penguin",1))
+ def test_crc32_adler32_unsigned(self):
+ foo = 'abcdefghijklmnop'
+ # explicitly test signed behavior
+ self.assertEqual(zlib.crc32(foo), 2486878355)
+ self.assertEqual(zlib.crc32('spam'), 1138425661)
+ self.assertEqual(zlib.adler32(foo+foo), 3573550353)
+ self.assertEqual(zlib.adler32('spam'), 72286642)
+
class ExceptionTestCase(unittest.TestCase):
if (!PyArg_ParseTuple(args, "s#|k:adler32", &buf, &len, &adler32val))
return NULL;
adler32val = adler32(adler32val, buf, len);
- return PyLong_FromLong(adler32val);
+ return PyLong_FromUnsignedLong(adler32val & 0xffffffff);
}
PyDoc_STRVAR(crc32__doc__,
if (!PyArg_ParseTuple(args, "s#|k:crc32", &buf, &len, &crc32val))
return NULL;
crc32val = crc32(crc32val, buf, len);
- return PyLong_FromLong(crc32val);
+ return PyLong_FromUnsignedLong(crc32val & 0xffffffff);
}