Page MenuHomePhabricator

Python2/3 compatibility - StringIO

Authored by serge-sans-paille on Dec 3 2018, 2:40 AM.

Diff Detail


Event Timeline

serge-sans-paille retitled this revision from Python2/3 compatibility to Python2/3 compatibility - StringIO.Dec 3 2018, 2:52 AM

Can you comment on whether the differences between StringIO and io.StringIO might be significant?

joerg added inline comments.Dec 3 2018, 4:10 AM
96 ↗(On Diff #176337)

Move it to the import list at the top of the file.

110 ↗(On Diff #176337)

This and the following cases want byte IO, don't they?

StringIO is obsoleted in python3, replaced by io.StringIO.
Yet io.StringIO only handles unicode string, while StringIO.StringIO only handles str, i.e. bytes.
serge-sans-paille marked an inline comment as done.Dec 3 2018, 5:35 AM
serge-sans-paille added inline comments.
110 ↗(On Diff #176337)

Yeah, it's probably safer. It really depends on the content of `e`. It also appears that Python 2.7 supports io.BytesIO, so I'd rather use that uniformly.

Use BytesIO as a repalcement... it more closely matches StringIO.StringIO

Update StringIO conversion after more testing.

115 ↗(On Diff #176568)

With Python 2 this fails with:
TypeError: unicode argument expected, got 'str'

michaelplatings requested changes to this revision.Dec 18 2018, 9:32 AM
This revision now requires changes to proceed.Dec 18 2018, 9:32 AM
michaelplatings requested changes to this revision.Jan 2 2019, 9:50 AM
michaelplatings added inline comments.
97 ↗(On Diff #179060)

May as well make this >= 3

32 ↗(On Diff #179060)

May as well make this >= 3

17 ↗(On Diff #179060)

May as well make this >= 3

288 ↗(On Diff #179060)

Why is this necessary? send_string returns a BytesIO object so why create a different one?

This revision now requires changes to proceed.Jan 2 2019, 9:50 AM
serge-sans-paille marked 4 inline comments as done.
This revision is now accepted and ready to land.Jan 3 2019, 4:56 AM
This revision was automatically updated to reflect the committed changes.