mirror of
https://github.com/python/cpython.git
synced 2025-08-17 15:21:26 +00:00
Merged revisions 83442 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/release27-maint ................ r83442 | antoine.pitrou | 2010-08-01 22:13:11 +0200 (dim., 01 août 2010) | 10 lines Merged revisions 83440 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83440 | antoine.pitrou | 2010-08-01 22:08:46 +0200 (dim., 01 août 2010) | 4 lines Issue #8397: Raise an error when attempting to mix iteration and regular reads on a BZ2File object, rather than returning incorrect results. ........ ................
This commit is contained in:
parent
1fa5e059a4
commit
cdb63fbc57
3 changed files with 49 additions and 0 deletions
|
@ -302,6 +302,24 @@ class BZ2FileTest(BaseTest):
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def testMixedIterationReads(self):
|
||||||
|
# Issue #8397: mixed iteration and reads should be forbidden.
|
||||||
|
f = bz2.BZ2File(self.filename, 'wb')
|
||||||
|
try:
|
||||||
|
# The internal buffer size is hard-wired to 8192 bytes, we must
|
||||||
|
# write out more than that for the test to stop half through
|
||||||
|
# the buffer.
|
||||||
|
f.write(self.TEXT * 100)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
|
f = bz2.BZ2File(self.filename, 'rb')
|
||||||
|
try:
|
||||||
|
next(f)
|
||||||
|
self.assertRaises(ValueError, f.read)
|
||||||
|
self.assertRaises(ValueError, f.readline)
|
||||||
|
self.assertRaises(ValueError, f.readlines)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
|
|
||||||
class BZ2CompressorTest(BaseTest):
|
class BZ2CompressorTest(BaseTest):
|
||||||
def testCompress(self):
|
def testCompress(self):
|
||||||
|
|
|
@ -84,6 +84,9 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #8397: Raise an error when attempting to mix iteration and regular
|
||||||
|
reads on a BZ2File object, rather than returning incorrect results.
|
||||||
|
|
||||||
- Issue #8620: when a Cmd is fed input that reaches EOF without a final
|
- Issue #8620: when a Cmd is fed input that reaches EOF without a final
|
||||||
newline, it no longer truncates the last character of the last command line.
|
newline, it no longer truncates the last character of the last command line.
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,22 @@ typedef struct {
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
/* Utility functions. */
|
/* Utility functions. */
|
||||||
|
|
||||||
|
/* Refuse regular I/O if there's data in the iteration-buffer.
|
||||||
|
* Mixing them would cause data to arrive out of order, as the read*
|
||||||
|
* methods don't use the iteration buffer. */
|
||||||
|
static int
|
||||||
|
check_iterbuffered(BZ2FileObject *f)
|
||||||
|
{
|
||||||
|
if (f->f_buf != NULL &&
|
||||||
|
(f->f_bufend - f->f_bufptr) > 0 &&
|
||||||
|
f->f_buf[0] != '\0') {
|
||||||
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
"Mixing iteration and read methods would lose data");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
Util_CatchBZ2Error(int bzerror)
|
Util_CatchBZ2Error(int bzerror)
|
||||||
{
|
{
|
||||||
|
@ -527,6 +543,10 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* refuse to mix with f.next() */
|
||||||
|
if (check_iterbuffered(self))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (bytesrequested < 0)
|
if (bytesrequested < 0)
|
||||||
buffersize = Util_NewBufferSize((size_t)0);
|
buffersize = Util_NewBufferSize((size_t)0);
|
||||||
else
|
else
|
||||||
|
@ -612,6 +632,10 @@ BZ2File_readline(BZ2FileObject *self, PyObject *args)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* refuse to mix with f.next() */
|
||||||
|
if (check_iterbuffered(self))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (sizehint == 0)
|
if (sizehint == 0)
|
||||||
ret = PyString_FromString("");
|
ret = PyString_FromString("");
|
||||||
else
|
else
|
||||||
|
@ -669,6 +693,10 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* refuse to mix with f.next() */
|
||||||
|
if (check_iterbuffered(self))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if ((list = PyList_New(0)) == NULL)
|
if ((list = PyList_New(0)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue