Roundup Tracker - Issues

Message6541

Author rouilj
Recipients ezio.melotti, joseph_myers, rouilj
Date 2019-06-09.01:23:25
Message-id <1560043406.12.0.463915338123.issue2551046@roundup.psfhosted.org>
In-reply-to
I have committed rev5775:17e110426ad7 preserving the super call.

The diff is:

diff -r 765f8c0e99ef -r 17e110426ad7 roundup/cgi/client.py
--- a/roundup/cgi/client.py     Fri Jun 07 21:53:55 2019 -0400
+++ b/roundup/cgi/client.py     Sat Jun 08 21:10:39 2019 -0400
@@ -230,7 +230,8 @@
         if set_cookie:
             self.client.add_cookie(self.cookie_name, self._sid, 
expire=expire)
 
-class BinaryFieldStorage(cgi.FieldStorage):
+# import from object as well so it's a new style object and I can use 
super()
+class BinaryFieldStorage(cgi.FieldStorage, object):
     '''This class works around the bug https://bugs.python.org/issue27777.
 
        cgi.FieldStorage must save all data as binary/bytes. This is
@@ -243,7 +244,7 @@
         import tempfile
         if self.length >= 0:
             return tempfile.TemporaryFile("wb+")
-        return super().make_file()
+        return super(BinaryFieldStorage, self).make_file()
 
 class Client:
     """Instantiate to handle one CGI request.

I arrived at this thanks to modifying an example from Ezio.
I have attached the modified example as test.py.

There were three ways to handle this:

  1) make sure super is never called on python 2 using the 'or ...'
     clause Joseph initially suggested. Workable but seemed like it
     wasn't in the python spirit.

  2) Use my suggested rewrite to call the base class directly. Joseph
     was correct that it shouldn't be:

         return cgi.FieldStorage().make_file()

     Ezio produced an earlier version of test.py that showed the 
     call should be:

                 return cgi.FieldStorage().make_file(self)

    which addresses Joseph's issue if I were to go this way.

  3) The patch above which is also shown in test.py makes
     BinaryFieldStorage inherit from object as well which makes
     super() when called using python2 and python 3 compatible
     semantics as super(BaseFieldStorage, self).... work.

test.py when run under py2 and py3 produces:

10
50
10
50

showing that super works as expected in this case.

I still can't figure out how to trigger this test case by calling
Client. But I am able to trigger both code paths manually using binary
and text data.

Comments?

-- rouilj
History
Date User Action Args
2019-06-09 01:23:26rouiljsetmessageid: <1560043406.12.0.463915338123.issue2551046@roundup.psfhosted.org>
2019-06-09 01:23:26rouiljsetrecipients: + rouilj, ezio.melotti, joseph_myers
2019-06-09 01:23:26rouiljlinkissue2551046 messages
2019-06-09 01:23:25rouiljcreate