How can I wrap a binary file-like object with an IO stream?
will at willmcgugan.com
Thu Mar 21 23:44:52 CET 2013
I am looking in to improving Python 3.X support for PyFilesystem (https://
There is provisional Python 3 support in there, but a stumbling block is
that I would like the open method to work like io.open in Py3 --
specifically returning text mode streams that handle the unicode encoding/
decoding. At the moment, the 'open' method of PyFilesystem objects just
returns a Python 2 style file-like object.
What I could use is a way of taking a Python 2.X file-like object
together with the mode, encoding and buffering etc. and return an
appropriate IO stream that handles the encoding/decoding.
I'm sure I could implement the logic myself by looking at the mode/
encoding and return the appropriate IO interface, but I was hoping there
was something in the stdlib to do this, or some pre-existing code I can
Thanks in advance,
More information about the Python-list