Make BZ2File's fileobj support easier to use.

The fileobj argument was added during the 3.3 development cycle, so this change
does not break backward compatibility with 3.2.
This commit is contained in:
Nadeem Vawda 2012-06-04 23:31:20 +02:00
parent 68721019ef
commit aebcdba829
5 changed files with 49 additions and 31 deletions

View file

@ -26,17 +26,18 @@ All of the classes in this module may safely be accessed from multiple threads.
(De)compression of files
------------------------
.. class:: BZ2File(filename=None, mode='r', buffering=None, compresslevel=9, \*, fileobj=None)
.. class:: BZ2File(filename, mode='r', buffering=None, compresslevel=9)
Open a bzip2-compressed file.
The :class:`BZ2File` can wrap an existing :term:`file object` (given by
*fileobj*), or operate directly on a named file (named by *filename*).
Exactly one of these two parameters should be provided.
If *filename* is a :class:`str` or :class:`bytes` object, open the named file
directly. Otherwise, *filename* should be a :term:`file object`, which will
be used to read or write the compressed data.
The *mode* argument can be either ``'r'`` for reading (default), ``'w'`` for
overwriting, or ``'a'`` for appending. If *fileobj* is provided, a mode of
``'w'`` does not truncate the file, and is instead equivalent to ``'a'``.
overwriting, or ``'a'`` for appending. If *filename* is a file object (rather
than an actual file name), a mode of ``'w'`` does not truncate the file, and
is instead equivalent to ``'a'``.
The *buffering* argument is ignored. Its use is deprecated.
@ -69,7 +70,8 @@ All of the classes in this module may safely be accessed from multiple threads.
:meth:`read1` and :meth:`readinto` methods were added.
.. versionchanged:: 3.3
The *fileobj* argument to the constructor was added.
Support was added for *filename* being a :term:`file object` instead of an
actual filename.
.. versionchanged:: 3.3
The ``'a'`` (append) mode was added, along with support for reading