Re: Need help getting my latest rest patches to have python3 compatibility
Joseph Myers <[email protected]>
| Newsgroups | gmane.comp.bug-tracking.roundup.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sun, 17 Mar 2019, John P. Rouillard wrote:
> >On Sun, 10 Mar 2019, John P. Rouillard wrote:
> >
> >> using ByteIO (in place of StringIO)
> >
> >That was correct. FieldStorage requires a file using bytes, not one using
> >strings.
>
> Well I think I have something working after much fiddling. Thanks for
> confirming BytesIO is the right thing to use. It seems like I am just
> throwing stuff at a wall and seeing what works.
My observation (and thus the patch I committed) is based on the
FieldStorage implementation saying:
file: the file(-like) object from which you can read the data *as
bytes* ; None if the data is stored a simple string
(I can't find other documentation for the interface to the FieldStorage
constructor).
> I am overriding the make_file routine for FieldStorage in client.py. I
> force it to always open the temp file in binary mode.
client.py does
self.form = cgi.FieldStorage(fp=request.rfile, environ=env)
where request.rfile should already be using bytes not str. I'm not sure
what make_file is meant to be used for.
> >I've applied some general Python 3 fixes for the REST code, as needed to
> >be able to get any JSON data from the REST interface at all (in a browser
> >as opposed to in the testsuite) when roundup-server is using Python 3,
> >and fixes for the tests to use bytes where appropriate.
>
> I needed to have the rest dispatch routine apply a bs2b() to the
> returned value.
The patch I committed used s2b. I didn't see any way you could have a
bytes value before conversion.
> Plus removal of getheader in Python 3 means all the calls like:
>
> headers.getheader('X-HTTP-Method-Override')
>
> need to be replaced by things like:
>
> override = None
> if 'X-HTTP-Method-Override' in headers:
> override = headers['X-HTTP-Method-Override']
Does .get (which is what I used in my commit) not work for this?
--
Joseph S. Myers
[email protected]