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