mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
Issue #16304: Further performance improvements for BZ2File.
Optimizations suggested by Serhiy Storchaka.
This commit is contained in:
parent
d2489cf4d0
commit
b7a0bfe912
1 changed files with 9 additions and 3 deletions
12
Lib/bz2.py
12
Lib/bz2.py
|
|
@ -159,15 +159,21 @@ class BZ2File(io.BufferedIOBase):
|
|||
raise ValueError("I/O operation on closed file")
|
||||
|
||||
def _check_can_read(self):
|
||||
if not self.readable():
|
||||
if self.closed:
|
||||
raise ValueError("I/O operation on closed file")
|
||||
if self._mode not in (_MODE_READ, _MODE_READ_EOF):
|
||||
raise io.UnsupportedOperation("File not open for reading")
|
||||
|
||||
def _check_can_write(self):
|
||||
if not self.writable():
|
||||
if self.closed:
|
||||
raise ValueError("I/O operation on closed file")
|
||||
if self._mode != _MODE_WRITE:
|
||||
raise io.UnsupportedOperation("File not open for writing")
|
||||
|
||||
def _check_can_seek(self):
|
||||
if not self.readable():
|
||||
if self.closed:
|
||||
raise ValueError("I/O operation on closed file")
|
||||
if self._mode not in (_MODE_READ, _MODE_READ_EOF):
|
||||
raise io.UnsupportedOperation("Seeking is only supported "
|
||||
"on files open for reading")
|
||||
if not self._fp.seekable():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue