cpython: a19f47d380d2 (original) (raw)
Mercurial > cpython
changeset 79382:a19f47d380d2
Merge: #16304: Optimizations for BZ2File, and minor bugfix. [#16304]
Nadeem Vawda nadeem.vawda@gmail.com | |
---|---|
date | Mon, 01 Oct 2012 23:11:35 +0200 |
parents | fb90e2ff95b7(current diff)6d7bf512e0c3(diff) |
children | 112103a4241a |
files | |
diffstat | 1 files changed, 12 insertions(+), 12 deletions(-)[+] [-] Lib/bz2.py 24 |
line wrap: on
line diff
--- a/Lib/bz2.py +++ b/Lib/bz2.py @@ -159,21 +159,18 @@ class BZ2File(io.BufferedIOBase): raise ValueError("I/O operation on closed file") def _check_can_read(self):
if self.closed:[](#l1.7)
raise ValueError("I/O operation on closed file")[](#l1.8) if self._mode not in (_MODE_READ, _MODE_READ_EOF):[](#l1.9)
self._check_not_closed()[](#l1.10) raise io.UnsupportedOperation("File not open for reading")[](#l1.11)
if self.closed:[](#l1.14)
raise ValueError("I/O operation on closed file")[](#l1.15) if self._mode != _MODE_WRITE:[](#l1.16)
self._check_not_closed()[](#l1.17) raise io.UnsupportedOperation("File not open for writing")[](#l1.18)
if self.closed:[](#l1.21)
raise ValueError("I/O operation on closed file")[](#l1.22) if self._mode not in (_MODE_READ, _MODE_READ_EOF):[](#l1.23)
self._check_not_closed()[](#l1.24) raise io.UnsupportedOperation("Seeking is only supported "[](#l1.25) "on files open for reading")[](#l1.26) if not self._fp.seekable():[](#l1.27)
@@ -322,10 +319,12 @@ class BZ2File(io.BufferedIOBase): non-negative, no more than size bytes will be read (in which case the line may be incomplete). Returns b'' if already at EOF. """
if not hasattr(size, "__index__"):[](#l1.32)
raise TypeError("Integer argument expected")[](#l1.33)
size = size.__index__()[](#l1.34)
if not isinstance(size, int):[](#l1.35)
if not hasattr(size, "__index__"):[](#l1.36)
raise TypeError("Integer argument expected")[](#l1.37)
size = size.__index__()[](#l1.38) with self._lock:[](#l1.39)
self._check_can_read()[](#l1.40) # Shortcut for the common case - the whole line is in the buffer.[](#l1.41) if size < 0:[](#l1.42) end = self._buffer.find(b"\n", self._buffer_offset) + 1[](#l1.43)
@@ -343,9 +342,10 @@ class BZ2File(io.BufferedIOBase): further lines will be read once the total size of the lines read so far equals or exceeds size. """
if not hasattr(size, "__index__"):[](#l1.48)
raise TypeError("Integer argument expected")[](#l1.49)
size = size.__index__()[](#l1.50)
if not isinstance(size, int):[](#l1.51)
if not hasattr(size, "__index__"):[](#l1.52)
raise TypeError("Integer argument expected")[](#l1.53)
size = size.__index__()[](#l1.54) with self._lock:[](#l1.55) return io.BufferedIOBase.readlines(self, size)[](#l1.56)