mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
Reformat!
Consistently indent 4 spaces. Use whitespace around operators. Put braces in the right places.
This commit is contained in:
parent
3c28863e08
commit
9714f99d60
1 changed files with 575 additions and 585 deletions
|
@ -177,8 +177,7 @@ PyZlib_compress(PyObject *self, PyObject *args)
|
||||||
"Bad compression level");
|
"Bad compression level");
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
if (zst.msg == Z_NULL)
|
if (zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError, "Error %i while compressing data",
|
PyErr_Format(ZlibError, "Error %i while compressing data",
|
||||||
err);
|
err);
|
||||||
|
@ -191,17 +190,16 @@ PyZlib_compress(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!return_error) {
|
if (!return_error) {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
err=deflate(&zst, Z_FINISH);
|
err=deflate(&zst, Z_FINISH);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
switch(err)
|
switch(err)
|
||||||
{
|
{
|
||||||
case(Z_STREAM_END):
|
case(Z_STREAM_END):
|
||||||
break;
|
break;
|
||||||
/* Are there other errors to be trapped here? */
|
/* Are there other errors to be trapped here? */
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
if (zst.msg == Z_NULL)
|
if (zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError, "Error %i while compressing data",
|
PyErr_Format(ZlibError, "Error %i while compressing data",
|
||||||
err);
|
err);
|
||||||
|
@ -218,11 +216,12 @@ PyZlib_compress(PyObject *self, PyObject *args)
|
||||||
if (!return_error) {
|
if (!return_error) {
|
||||||
err=deflateEnd(&zst);
|
err=deflateEnd(&zst);
|
||||||
if (err == Z_OK)
|
if (err == Z_OK)
|
||||||
ReturnVal = PyString_FromStringAndSize((char *)output, zst.total_out);
|
ReturnVal = PyString_FromStringAndSize((char *)output,
|
||||||
|
zst.total_out);
|
||||||
else {
|
else {
|
||||||
{
|
|
||||||
if (zst.msg == Z_NULL)
|
if (zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError, "Error %i while finishing compression",
|
PyErr_Format(ZlibError,
|
||||||
|
"Error %i while finishing compression",
|
||||||
err);
|
err);
|
||||||
else
|
else
|
||||||
PyErr_Format(ZlibError,
|
PyErr_Format(ZlibError,
|
||||||
|
@ -230,8 +229,6 @@ PyZlib_compress(PyObject *self, PyObject *args)
|
||||||
err, zst.msg);
|
err, zst.msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(output);
|
free(output);
|
||||||
|
@ -257,7 +254,8 @@ PyZlib_decompress(PyObject *self, PyObject *args)
|
||||||
int return_error;
|
int return_error;
|
||||||
PyObject * inputString;
|
PyObject * inputString;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "S|ii:decompress", &inputString, &wsize, &r_strlen))
|
if (!PyArg_ParseTuple(args, "S|ii:decompress",
|
||||||
|
&inputString, &wsize, &r_strlen))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (PyString_AsStringAndSize(inputString, (char**)&input, &length) == -1)
|
if (PyString_AsStringAndSize(inputString, (char**)&input, &length) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -265,11 +263,10 @@ PyZlib_decompress(PyObject *self, PyObject *args)
|
||||||
if (r_strlen <= 0)
|
if (r_strlen <= 0)
|
||||||
r_strlen = 1;
|
r_strlen = 1;
|
||||||
|
|
||||||
zst.avail_in=length;
|
zst.avail_in = length;
|
||||||
zst.avail_out=r_strlen;
|
zst.avail_out = r_strlen;
|
||||||
|
|
||||||
if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen)))
|
if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen))) {
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_MemoryError,
|
PyErr_SetString(PyExc_MemoryError,
|
||||||
"Can't allocate memory to decompress data");
|
"Can't allocate memory to decompress data");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -280,23 +277,21 @@ PyZlib_decompress(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
Py_INCREF(inputString); /* increment so that we hold ref */
|
Py_INCREF(inputString); /* increment so that we hold ref */
|
||||||
|
|
||||||
zst.zalloc=(alloc_func)NULL;
|
zst.zalloc = (alloc_func)NULL;
|
||||||
zst.zfree=(free_func)Z_NULL;
|
zst.zfree = (free_func)Z_NULL;
|
||||||
zst.next_out=(Byte *)PyString_AsString(result_str);
|
zst.next_out = (Byte *)PyString_AsString(result_str);
|
||||||
zst.next_in =(Byte *)input;
|
zst.next_in = (Byte *)input;
|
||||||
err=inflateInit2(&zst, wsize);
|
err = inflateInit2(&zst, wsize);
|
||||||
|
|
||||||
return_error = 0;
|
return_error = 0;
|
||||||
switch(err)
|
switch(err) {
|
||||||
{
|
|
||||||
case(Z_OK):
|
case(Z_OK):
|
||||||
break;
|
break;
|
||||||
case(Z_MEM_ERROR):
|
case(Z_MEM_ERROR):
|
||||||
PyErr_SetString(PyExc_MemoryError,
|
PyErr_SetString(PyExc_MemoryError,
|
||||||
"Out of memory while decompressing data");
|
"Out of memory while decompressing data");
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
if (zst.msg == Z_NULL)
|
if (zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError, "Error %i preparing to decompress data",
|
PyErr_Format(ZlibError, "Error %i preparing to decompress data",
|
||||||
err);
|
err);
|
||||||
|
@ -310,8 +305,7 @@ PyZlib_decompress(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
if (return_error)
|
if (return_error)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -319,8 +313,7 @@ PyZlib_decompress(PyObject *self, PyObject *args)
|
||||||
err=inflate(&zst, Z_FINISH);
|
err=inflate(&zst, Z_FINISH);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
switch(err)
|
switch(err) {
|
||||||
{
|
|
||||||
case(Z_STREAM_END):
|
case(Z_STREAM_END):
|
||||||
break;
|
break;
|
||||||
case(Z_BUF_ERROR):
|
case(Z_BUF_ERROR):
|
||||||
|
@ -340,20 +333,19 @@ PyZlib_decompress(PyObject *self, PyObject *args)
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case(Z_OK):
|
case(Z_OK):
|
||||||
/* need more memory */
|
/* need more memory */
|
||||||
if (_PyString_Resize(&result_str, r_strlen << 1) == -1)
|
if (_PyString_Resize(&result_str, r_strlen << 1) == -1) {
|
||||||
{
|
|
||||||
PyErr_SetString(PyExc_MemoryError,
|
PyErr_SetString(PyExc_MemoryError,
|
||||||
"Out of memory while decompressing data");
|
"Out of memory while decompressing data");
|
||||||
inflateEnd(&zst);
|
inflateEnd(&zst);
|
||||||
result_str = NULL;
|
result_str = NULL;
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
}
|
}
|
||||||
zst.next_out = (unsigned char *)PyString_AsString(result_str) + r_strlen;
|
zst.next_out = (unsigned char *)PyString_AsString(result_str) \
|
||||||
zst.avail_out=r_strlen;
|
+ r_strlen;
|
||||||
|
zst.avail_out = r_strlen;
|
||||||
r_strlen = r_strlen << 1;
|
r_strlen = r_strlen << 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
if (zst.msg == Z_NULL)
|
if (zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError, "Error %i while decompressing data",
|
PyErr_Format(ZlibError, "Error %i while decompressing data",
|
||||||
err);
|
err);
|
||||||
|
@ -365,12 +357,11 @@ PyZlib_decompress(PyObject *self, PyObject *args)
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while(err!=Z_STREAM_END);
|
} while (err != Z_STREAM_END);
|
||||||
|
|
||||||
if (!return_error) {
|
if (!return_error) {
|
||||||
err=inflateEnd(&zst);
|
err = inflateEnd(&zst);
|
||||||
if (err!=Z_OK)
|
if (err != Z_OK) {
|
||||||
{
|
|
||||||
if (zst.msg == Z_NULL)
|
if (zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError,
|
PyErr_Format(ZlibError,
|
||||||
"Error %i while finishing data decompression",
|
"Error %i while finishing data decompression",
|
||||||
|
@ -387,9 +378,8 @@ PyZlib_decompress(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
if (!return_error)
|
if (!return_error)
|
||||||
_PyString_Resize(&result_str, zst.total_out);
|
_PyString_Resize(&result_str, zst.total_out);
|
||||||
else {
|
else
|
||||||
Py_XDECREF(result_str); /* sets result_str == NULL, if not already */
|
Py_XDECREF(result_str); /* sets result_str == NULL, if not already */
|
||||||
}
|
|
||||||
Py_DECREF(inputString);
|
Py_DECREF(inputString);
|
||||||
|
|
||||||
return result_str;
|
return result_str;
|
||||||
|
@ -569,7 +559,8 @@ PyZlib_objcompress(compobject *self, PyObject *args)
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) + length;
|
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) \
|
||||||
|
+ length;
|
||||||
self->zst.avail_out = length;
|
self->zst.avail_out = length;
|
||||||
length = length << 1;
|
length = length << 1;
|
||||||
|
|
||||||
|
@ -577,8 +568,10 @@ PyZlib_objcompress(compobject *self, PyObject *args)
|
||||||
err = deflate(&(self->zst), Z_NO_FLUSH);
|
err = deflate(&(self->zst), Z_NO_FLUSH);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
}
|
}
|
||||||
/* We will only get Z_BUF_ERROR if the output buffer was full but there
|
/* We will only get Z_BUF_ERROR if the output buffer was full but
|
||||||
wasn't more output when we tried again, so it is not an error condition */
|
there wasn't more output when we tried again, so it is not an error
|
||||||
|
condition.
|
||||||
|
*/
|
||||||
|
|
||||||
if (!return_error) {
|
if (!return_error) {
|
||||||
if (err != Z_OK && err != Z_BUF_ERROR) {
|
if (err != Z_OK && err != Z_BUF_ERROR) {
|
||||||
|
@ -685,7 +678,8 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal)+old_length;
|
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) \
|
||||||
|
+ old_length;
|
||||||
self->zst.avail_out = length - old_length;
|
self->zst.avail_out = length - old_length;
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
@ -703,24 +697,27 @@ PyZlib_objdecompress(compobject *self, PyObject *args)
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The end of the compressed data has been reached, so set the unused_data
|
/* The end of the compressed data has been reached, so set the
|
||||||
attribute to a string containing the remainder of the data in the string.
|
unused_data attribute to a string containing the remainder of the
|
||||||
Note that this is also a logical place to call inflateEnd, but the old
|
data in the string. Note that this is also a logical place to call
|
||||||
behaviour of only calling it on flush() is preserved.*/
|
inflateEnd, but the old behaviour of only calling it on flush() is
|
||||||
|
preserved.
|
||||||
|
*/
|
||||||
if (!return_error) {
|
if (!return_error) {
|
||||||
if (err == Z_STREAM_END) {
|
if (err == Z_STREAM_END) {
|
||||||
Py_XDECREF(self->unused_data); /* Free the original, empty string */
|
Py_XDECREF(self->unused_data); /* Free original empty string */
|
||||||
self->unused_data = PyString_FromStringAndSize((char *)self->zst.next_in,
|
self->unused_data = PyString_FromStringAndSize(
|
||||||
self->zst.avail_in);
|
(char *)self->zst.next_in, self->zst.avail_in);
|
||||||
if (self->unused_data == NULL) {
|
if (self->unused_data == NULL) {
|
||||||
PyErr_SetString(PyExc_MemoryError,
|
PyErr_SetString(PyExc_MemoryError,
|
||||||
"Can't allocate memory to unused_data");
|
"Can't allocate memory to unused_data");
|
||||||
Py_DECREF(RetVal);
|
Py_DECREF(RetVal);
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
}
|
}
|
||||||
/* We will only get Z_BUF_ERROR if the output buffer was full but there
|
/* We will only get Z_BUF_ERROR if the output buffer was full
|
||||||
wasn't more output when we tried again, so it is not an error
|
but there wasn't more output when we tried again, so it is
|
||||||
condition */
|
not an error condition.
|
||||||
|
*/
|
||||||
} else if (err != Z_OK && err != Z_BUF_ERROR) {
|
} else if (err != Z_OK && err != Z_BUF_ERROR) {
|
||||||
if (self->zst.msg == Z_NULL)
|
if (self->zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError, "Error %i while decompressing",
|
PyErr_Format(ZlibError, "Error %i while decompressing",
|
||||||
|
@ -757,7 +754,7 @@ static char comp_flush__doc__[] =
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PyZlib_flush(compobject *self, PyObject *args)
|
PyZlib_flush(compobject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
int err, length=DEFAULTALLOC;
|
int err, length = DEFAULTALLOC;
|
||||||
PyObject *RetVal;
|
PyObject *RetVal;
|
||||||
int flushmode = Z_FINISH;
|
int flushmode = Z_FINISH;
|
||||||
unsigned long start_total_out;
|
unsigned long start_total_out;
|
||||||
|
@ -800,7 +797,8 @@ PyZlib_flush(compobject *self, PyObject *args)
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) + length;
|
self->zst.next_out = (unsigned char *)PyString_AsString(RetVal) \
|
||||||
|
+ length;
|
||||||
self->zst.avail_out = length;
|
self->zst.avail_out = length;
|
||||||
length = length << 1;
|
length = length << 1;
|
||||||
|
|
||||||
|
@ -814,24 +812,25 @@ PyZlib_flush(compobject *self, PyObject *args)
|
||||||
flushmode is Z_FINISH, but checking both for safety*/
|
flushmode is Z_FINISH, but checking both for safety*/
|
||||||
if (!return_error) {
|
if (!return_error) {
|
||||||
if (err == Z_STREAM_END && flushmode == Z_FINISH) {
|
if (err == Z_STREAM_END && flushmode == Z_FINISH) {
|
||||||
err=deflateEnd(&(self->zst));
|
err = deflateEnd(&(self->zst));
|
||||||
if (err!=Z_OK) {
|
if (err != Z_OK) {
|
||||||
if (self->zst.msg == Z_NULL)
|
if (self->zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError, "Error %i from deflateEnd()",
|
PyErr_Format(ZlibError, "Error %i from deflateEnd()",
|
||||||
err);
|
err);
|
||||||
else
|
else
|
||||||
PyErr_Format(ZlibError,"Error %i from deflateEnd(): %.200s",
|
PyErr_Format(ZlibError,
|
||||||
|
"Error %i from deflateEnd(): %.200s",
|
||||||
err, self->zst.msg);
|
err, self->zst.msg);
|
||||||
|
|
||||||
Py_DECREF(RetVal);
|
Py_DECREF(RetVal);
|
||||||
return_error = 1;
|
return_error = 1;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
self->is_initialised = 0;
|
self->is_initialised = 0;
|
||||||
|
|
||||||
/* We will only get Z_BUF_ERROR if the output buffer was full but there
|
/* We will only get Z_BUF_ERROR if the output buffer was full
|
||||||
wasn't more output when we tried again, so it is not an error
|
but there wasn't more output when we tried again, so it is
|
||||||
condition */
|
not an error condition.
|
||||||
|
*/
|
||||||
} else if (err!=Z_OK && err!=Z_BUF_ERROR) {
|
} else if (err!=Z_OK && err!=Z_BUF_ERROR) {
|
||||||
if (self->zst.msg == Z_NULL)
|
if (self->zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError, "Error %i while flushing",
|
PyErr_Format(ZlibError, "Error %i while flushing",
|
||||||
|
@ -874,8 +873,8 @@ PyZlib_unflush(compobject *self, PyObject *args)
|
||||||
|
|
||||||
ENTER_ZLIB
|
ENTER_ZLIB
|
||||||
|
|
||||||
err=inflateEnd(&(self->zst));
|
err = inflateEnd(&(self->zst));
|
||||||
if (err!=Z_OK) {
|
if (err != Z_OK) {
|
||||||
if (self->zst.msg == Z_NULL)
|
if (self->zst.msg == Z_NULL)
|
||||||
PyErr_Format(ZlibError, "Error %i from inflateEnd()",
|
PyErr_Format(ZlibError, "Error %i from inflateEnd()",
|
||||||
err);
|
err);
|
||||||
|
@ -884,7 +883,6 @@ PyZlib_unflush(compobject *self, PyObject *args)
|
||||||
err, self->zst.msg);
|
err, self->zst.msg);
|
||||||
|
|
||||||
retval = NULL;
|
retval = NULL;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
self->is_initialised = 0;
|
self->is_initialised = 0;
|
||||||
retval = PyString_FromStringAndSize(NULL, 0);
|
retval = PyString_FromStringAndSize(NULL, 0);
|
||||||
|
@ -897,19 +895,19 @@ PyZlib_unflush(compobject *self, PyObject *args)
|
||||||
|
|
||||||
static PyMethodDef comp_methods[] =
|
static PyMethodDef comp_methods[] =
|
||||||
{
|
{
|
||||||
{"compress", (binaryfunc)PyZlib_objcompress,
|
{"compress", (binaryfunc)PyZlib_objcompress, METH_VARARGS,
|
||||||
METH_VARARGS, comp_compress__doc__},
|
comp_compress__doc__},
|
||||||
{"flush", (binaryfunc)PyZlib_flush,
|
{"flush", (binaryfunc)PyZlib_flush, METH_VARARGS,
|
||||||
METH_VARARGS, comp_flush__doc__},
|
comp_flush__doc__},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyMethodDef Decomp_methods[] =
|
static PyMethodDef Decomp_methods[] =
|
||||||
{
|
{
|
||||||
{"decompress", (binaryfunc)PyZlib_objdecompress,
|
{"decompress", (binaryfunc)PyZlib_objdecompress, METH_VARARGS,
|
||||||
METH_VARARGS, decomp_decompress__doc__},
|
decomp_decompress__doc__},
|
||||||
{"flush", (binaryfunc)PyZlib_unflush,
|
{"flush", (binaryfunc)PyZlib_unflush, METH_VARARGS,
|
||||||
METH_VARARGS, decomp_flush__doc__},
|
decomp_flush__doc__},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -929,17 +927,13 @@ Decomp_getattr(compobject *self, char *name)
|
||||||
|
|
||||||
ENTER_ZLIB
|
ENTER_ZLIB
|
||||||
|
|
||||||
if (strcmp(name, "unused_data") == 0)
|
if (strcmp(name, "unused_data") == 0) {
|
||||||
{
|
|
||||||
Py_INCREF(self->unused_data);
|
Py_INCREF(self->unused_data);
|
||||||
retval = self->unused_data;
|
retval = self->unused_data;
|
||||||
}
|
} else if (strcmp(name, "unconsumed_tail") == 0) {
|
||||||
else if (strcmp(name, "unconsumed_tail") == 0)
|
|
||||||
{
|
|
||||||
Py_INCREF(self->unconsumed_tail);
|
Py_INCREF(self->unconsumed_tail);
|
||||||
retval = self->unconsumed_tail;
|
retval = self->unconsumed_tail;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
retval = Py_FindMethod(Decomp_methods, (PyObject *)self, name);
|
retval = Py_FindMethod(Decomp_methods, (PyObject *)self, name);
|
||||||
|
|
||||||
LEAVE_ZLIB
|
LEAVE_ZLIB
|
||||||
|
@ -957,14 +951,12 @@ static char adler32__doc__[] =
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PyZlib_adler32(PyObject *self, PyObject *args)
|
PyZlib_adler32(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
uLong adler32val=adler32(0L, Z_NULL, 0);
|
uLong adler32val = adler32(0L, Z_NULL, 0);
|
||||||
Byte *buf;
|
Byte *buf;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s#|l:adler32", &buf, &len, &adler32val))
|
if (!PyArg_ParseTuple(args, "s#|l:adler32", &buf, &len, &adler32val))
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
adler32val = adler32(adler32val, buf, len);
|
adler32val = adler32(adler32val, buf, len);
|
||||||
return PyInt_FromLong(adler32val);
|
return PyInt_FromLong(adler32val);
|
||||||
}
|
}
|
||||||
|
@ -979,13 +971,11 @@ static char crc32__doc__[] =
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PyZlib_crc32(PyObject *self, PyObject *args)
|
PyZlib_crc32(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
uLong crc32val=crc32(0L, Z_NULL, 0);
|
uLong crc32val = crc32(0L, Z_NULL, 0);
|
||||||
Byte *buf;
|
Byte *buf;
|
||||||
int len;
|
int len;
|
||||||
if (!PyArg_ParseTuple(args, "s#|l:crc32", &buf, &len, &crc32val))
|
if (!PyArg_ParseTuple(args, "s#|l:crc32", &buf, &len, &crc32val))
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
crc32val = crc32(crc32val, buf, len);
|
crc32val = crc32(crc32val, buf, len);
|
||||||
return PyInt_FromLong(crc32val);
|
return PyInt_FromLong(crc32val);
|
||||||
}
|
}
|
||||||
|
@ -993,18 +983,18 @@ PyZlib_crc32(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
static PyMethodDef zlib_methods[] =
|
static PyMethodDef zlib_methods[] =
|
||||||
{
|
{
|
||||||
{"adler32", (PyCFunction)PyZlib_adler32,
|
{"adler32", (PyCFunction)PyZlib_adler32, METH_VARARGS,
|
||||||
METH_VARARGS, adler32__doc__},
|
adler32__doc__},
|
||||||
{"compress", (PyCFunction)PyZlib_compress,
|
{"compress", (PyCFunction)PyZlib_compress, METH_VARARGS,
|
||||||
METH_VARARGS, compress__doc__},
|
compress__doc__},
|
||||||
{"compressobj", (PyCFunction)PyZlib_compressobj,
|
{"compressobj", (PyCFunction)PyZlib_compressobj, METH_VARARGS,
|
||||||
METH_VARARGS, compressobj__doc__},
|
compressobj__doc__},
|
||||||
{"crc32", (PyCFunction)PyZlib_crc32,
|
{"crc32", (PyCFunction)PyZlib_crc32, METH_VARARGS,
|
||||||
METH_VARARGS, crc32__doc__},
|
crc32__doc__},
|
||||||
{"decompress", (PyCFunction)PyZlib_decompress,
|
{"decompress", (PyCFunction)PyZlib_decompress, METH_VARARGS,
|
||||||
METH_VARARGS, decompress__doc__},
|
decompress__doc__},
|
||||||
{"decompressobj", (PyCFunction)PyZlib_decompressobj,
|
{"decompressobj", (PyCFunction)PyZlib_decompressobj, METH_VARARGS,
|
||||||
METH_VARARGS, decompressobj__doc__},
|
decompressobj__doc__},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1091,20 +1081,20 @@ PyInit_zlib(void)
|
||||||
if (ZlibError != NULL)
|
if (ZlibError != NULL)
|
||||||
PyDict_SetItemString(d, "error", ZlibError);
|
PyDict_SetItemString(d, "error", ZlibError);
|
||||||
|
|
||||||
insint(d, "MAX_WBITS", MAX_WBITS);
|
PyModule_AddIntConstant(m, "MAX_WBITS", MAX_WBITS);
|
||||||
insint(d, "DEFLATED", DEFLATED);
|
PyModule_AddIntConstant(m, "DEFLATED", DEFLATED);
|
||||||
insint(d, "DEF_MEM_LEVEL", DEF_MEM_LEVEL);
|
PyModule_AddIntConstant(m, "DEF_MEM_LEVEL", DEF_MEM_LEVEL);
|
||||||
insint(d, "Z_BEST_SPEED", Z_BEST_SPEED);
|
PyModule_AddIntConstant(m, "Z_BEST_SPEED", Z_BEST_SPEED);
|
||||||
insint(d, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION);
|
PyModule_AddIntConstant(m, "Z_BEST_COMPRESSION", Z_BEST_COMPRESSION);
|
||||||
insint(d, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION);
|
PyModule_AddIntConstant(m, "Z_DEFAULT_COMPRESSION", Z_DEFAULT_COMPRESSION);
|
||||||
insint(d, "Z_FILTERED", Z_FILTERED);
|
PyModule_AddIntConstant(m, "Z_FILTERED", Z_FILTERED);
|
||||||
insint(d, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY);
|
PyModule_AddIntConstant(m, "Z_HUFFMAN_ONLY", Z_HUFFMAN_ONLY);
|
||||||
insint(d, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY);
|
PyModule_AddIntConstant(m, "Z_DEFAULT_STRATEGY", Z_DEFAULT_STRATEGY);
|
||||||
|
|
||||||
insint(d, "Z_FINISH", Z_FINISH);
|
PyModule_AddIntConstant(m, "Z_FINISH", Z_FINISH);
|
||||||
insint(d, "Z_NO_FLUSH", Z_NO_FLUSH);
|
PyModule_AddIntConstant(m, "Z_NO_FLUSH", Z_NO_FLUSH);
|
||||||
insint(d, "Z_SYNC_FLUSH", Z_SYNC_FLUSH);
|
PyModule_AddIntConstant(m, "Z_SYNC_FLUSH", Z_SYNC_FLUSH);
|
||||||
insint(d, "Z_FULL_FLUSH", Z_FULL_FLUSH);
|
PyModule_AddIntConstant(m, "Z_FULL_FLUSH", Z_FULL_FLUSH);
|
||||||
|
|
||||||
ver = PyString_FromString(ZLIB_VERSION);
|
ver = PyString_FromString(ZLIB_VERSION);
|
||||||
if (ver != NULL) {
|
if (ver != NULL) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue