Re: Need help getting my latest rest patches to have python3 compatibility

"John P. Rouillard" <[email protected]>
Newsgroups gmane.comp.bug-tracking.roundup.devel
Message-ID <[email protected]>
Hi Joseph:

In message <[email protected]>,
Joseph Myers writes:
>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.

I am overriding the make_file routine for FieldStorage in client.py. I
force it to always open the temp file in binary mode.

Without this, making rest calls with python 3 running the tracker
crash. I think this is wrong, but I have no idea how to make it work
otherwise. The tests all pass even with this change, so hopefully I am
not breaking too much...

Any thoughts on this?

>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.

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']

>There is still a failure with Python 3 that I haven't fixed:
>
>>       self.assertEqual(json_dict['data']['type'], "<type 'str'>")
>E       AssertionError: "<class 'str'>" != "<type 'str'>"
>E       - <class 'str'>
>E       + <type 'str'>
>
>This relates to the different results from str(str) in Python 3 versus 
>Python 2.  Either the test needs to accept both variants or the REST code 
>need to do something to avoid this output depending on the Python version 
>used.

    self..assertIn(..., ("<type 'str'>", "<class 'str'>"))

to the rescue in the test case. I am just doing a final run under
python 2 and 3 of the tests I can run.

 I hope to check in and push this later today. Would you be able to
give it a look once it's uploaded?

Thanks for your feedback.
--
				-- rouilj
John Rouillard
===========================================================================
My employers don't acknowledge my existence much less my opinions.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.