Open maxgrenderjones opened 9 years ago
Having spent a while trying to fix this, there are a series of challenges:
gzip.open
/ bz2.BZ2File
are missing most of the methods that TextIOWrapper
depends on, so it's not a simple as copying over read1
gzip
version of the workaround above works, but bz2.BZ2File
is a C-like thing (not a pythonic object), so you can't assign arbitrary attributesgzip
/bz2
don't have an open
method (and the File
versions are still missing methods such as read1
which are required to get TextIOWrapper
to work), and if you don't call open
in 3.3+ with t
then newline behaviour isn't what you wantOne option would be to use external packages that work around this issue:
BZ2File
and open
)lzma
module which therefore has a modern API, even on earlier pythons, but requires a C module, you'd probably only want to make use of it if it was already available)gzip
)Thanks for looking into it! My philosophy is actually to only support 2.7 and 3.3+. I'll play around with a possible set of wrappers today, but the challenges you found are good to know.
The read-compressed-file modules all added a
't'
mode for opening files in text mode at the same time't'
was added as a mode for plain vanillaopen
. Is it possible to monkey-patch them so that they work too?P.S. sadly the answer isn't as simple as wrapping them in a
TextIOWrapper
as they only partially support thefile
protocol:(same issue on python 3.2 - works fine on 3.3)
One workaround that wfm (found at https://bugs.python.org/issue12591) is to alias
read
toread1
like so: