How can I wrap a binary file-like object with an IO stream?
Will McGugan
will at willmcgugan.com
Thu Mar 21 18:44:52 EDT 2013
Hi,
I am looking in to improving Python 3.X support for PyFilesystem (https://
code.google.com/p/pyfilesystem/).
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
lift?
Thanks in advance,
Will McGugan
--
http://www.willmcgugan.com
More information about the Python-list
mailing list