diff roundup/cgi/client.py @ 5775:17e110426ad7

issue2551046: Attempts to attach file or create large message fail under python2 This patch fixes a bug introduced for working around an issue in python3. There were a few ways to fix this, but I think this fix: 1) follows the spirit of the original patch 2) follows python programming expectations I am still having an issue trying to get both code paths executed from the test suite. The super code path is not tested, but I did validate that path from the browser and it works producing valid uploaded files in both python 2 and 3. Thanks to Ezio Melotti and Joseph Myers for their help in guiding me to come up with this solution.
author John Rouillard <rouilj@ieee.org>
date Sat, 08 Jun 2019 21:10:39 -0400
parents b67636bc87d0
children 0e6d45413e88
line wrap: on
line diff
--- 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.

Roundup Issue Tracker: http://roundup-tracker.org/