summaryrefslogtreecommitdiffstats
path: root/Lib/bz2.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-10-08 17:20:49 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-10-08 17:20:49 (GMT)
commit3b4a4f5199c7ee4d09f3efc86f3df2272846be8d (patch)
tree94fe2a0abf761f6ce25e0e6c408ea35ffc4049be /Lib/bz2.py
parentfc7b0ec5a209e1b36fa0e7ff3576c78558f18baa (diff)
downloadcpython-3b4a4f5199c7ee4d09f3efc86f3df2272846be8d.zip
cpython-3b4a4f5199c7ee4d09f3efc86f3df2272846be8d.tar.gz
cpython-3b4a4f5199c7ee4d09f3efc86f3df2272846be8d.tar.bz2
Stylistic tweaks to the bz2 module to make it easier to transplant changes from
it to http://pypi.python.org/pypi/bz2file.
Diffstat (limited to 'Lib/bz2.py')
-rw-r--r--Lib/bz2.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/bz2.py b/Lib/bz2.py
index c307507..3c9f4ef 100644
--- a/Lib/bz2.py
+++ b/Lib/bz2.py
@@ -9,7 +9,6 @@ __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor",
__author__ = "Nadeem Vawda <nadeem.vawda@gmail.com>"
-import builtins
import io
import warnings
@@ -28,6 +27,8 @@ _MODE_WRITE = 3
_BUFFER_SIZE = 8192
+_builtin_open = open
+
class BZ2File(io.BufferedIOBase):
@@ -90,10 +91,10 @@ class BZ2File(io.BufferedIOBase):
mode_code = _MODE_WRITE
self._compressor = BZ2Compressor(compresslevel)
else:
- raise ValueError("Invalid mode: {!r}".format(mode))
+ raise ValueError("Invalid mode: %r" % (mode,))
if isinstance(filename, (str, bytes)):
- self._fp = builtins.open(filename, mode)
+ self._fp = _builtin_open(filename, mode)
self._closefp = True
self._mode = mode_code
elif hasattr(filename, "read") or hasattr(filename, "write"):
@@ -189,15 +190,17 @@ class BZ2File(io.BufferedIOBase):
if not rawblock:
if self._decompressor.eof:
+ # End-of-stream marker and end of file. We're good.
self._mode = _MODE_READ_EOF
self._size = self._pos
return False
else:
+ # Problem - we were expecting more compressed data.
raise EOFError("Compressed file ended before the "
"end-of-stream marker was reached")
- # Continue to next stream.
if self._decompressor.eof:
+ # Continue to next stream.
self._decompressor = BZ2Decompressor()
self._buffer = self._decompressor.decompress(rawblock)
@@ -412,7 +415,7 @@ class BZ2File(io.BufferedIOBase):
self._read_all(return_data=False)
offset = self._size + offset
else:
- raise ValueError("Invalid value for whence: {}".format(whence))
+ raise ValueError("Invalid value for whence: %s" % (whence,))
# Make it so that offset is the number of bytes to skip forward.
if offset < self._pos: