diff roundup/cgi/client.py @ 5671:f60c44563c3a

Adjust make_file override to use binary files only when needed. Previous version would produce errors for large text fields in form submissions with Python 3, so inherit from the default make_file implementation and only force binary files in the specific case (self.length >= 0) identified in <https://bugs.python.org/issue27777>.
author Joseph Myers <jsm@polyomino.org.uk>
date Sun, 24 Mar 2019 21:49:17 +0000
parents d660d1c1ba63
children b67636bc87d0
line wrap: on
line diff
--- a/roundup/cgi/client.py	Sun Mar 24 12:52:03 2019 -0400
+++ b/roundup/cgi/client.py	Sun Mar 24 21:49:17 2019 +0000
@@ -237,15 +237,13 @@
        needed for handling json and xml data blobs under python
        3. Under python 2, str and binary are interchangable, not so
        under 3.
-
-       Note that there may be places where this should support text mode.
-       (e.g. a large text file upload??). None are known, but this could be
-       a problem.
     '''
     def make_file(self, mode=None):
         ''' work around https://bugs.python.org/issue27777 '''
         import tempfile
-        return tempfile.TemporaryFile("wb+")
+        if self.length >= 0:
+            return tempfile.TemporaryFile("wb+")
+        return super().make_file()
 
 class Client:
     """Instantiate to handle one CGI request.

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