diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-05-11 23:46:02 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-05-11 23:46:02 (GMT) |
commit | 53b2166f0ba2f63ec5711718e09f890c4fe09922 (patch) | |
tree | 98e4f2e68f73efa05b00c809f2ca8b0fc6b14271 /Modules | |
parent | c09c92fd81b05db4e5bfe5322f038ca1727fcde0 (diff) | |
download | cpython-53b2166f0ba2f63ec5711718e09f890c4fe09922.zip cpython-53b2166f0ba2f63ec5711718e09f890c4fe09922.tar.gz cpython-53b2166f0ba2f63ec5711718e09f890c4fe09922.tar.bz2 |
Merged revisions 81098 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81098 | antoine.pitrou | 2010-05-12 01:42:28 +0200 (mer., 12 mai 2010) | 5 lines
Issue #8681: Make the zlib module's error messages more informative when
the zlib itself doesn't give any detailed explanation.
........
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/zlibmodule.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 1f263ab..54ab9a1 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -52,10 +52,24 @@ typedef struct static void zlib_error(z_stream zst, int err, char *msg) { - if (zst.msg == Z_NULL) + const char *zmsg = zst.msg; + if (zmsg == Z_NULL) { + switch (err) { + case Z_BUF_ERROR: + zmsg = "incomplete or truncated stream"; + break; + case Z_STREAM_ERROR: + zmsg = "inconsistent stream state"; + break; + case Z_DATA_ERROR: + zmsg = "invalid input data"; + break; + } + } + if (zmsg == Z_NULL) PyErr_Format(ZlibError, "Error %d %s", err, msg); else - PyErr_Format(ZlibError, "Error %d %s: %.200s", err, msg, zst.msg); + PyErr_Format(ZlibError, "Error %d %s: %.200s", err, msg, zmsg); } PyDoc_STRVAR(compressobj__doc__, @@ -241,8 +255,7 @@ PyZlib_decompress(PyObject *self, PyObject *args) * process the inflate call() due to an error in the data. */ if (zst.avail_out > 0) { - PyErr_Format(ZlibError, "Error %i while decompressing data", - err); + zlib_error(zst, err, "while decompressing data"); inflateEnd(&zst); goto error; } |