Skip to content

Commit 5b8d733

Browse files
committed
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>.
1 parent b8013f0 commit 5b8d733

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

roundup/cgi/client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,13 @@ class BinaryFieldStorage(cgi.FieldStorage):
237237
needed for handling json and xml data blobs under python
238238
3. Under python 2, str and binary are interchangable, not so
239239
under 3.
240-
241-
Note that there may be places where this should support text mode.
242-
(e.g. a large text file upload??). None are known, but this could be
243-
a problem.
244240
'''
245241
def make_file(self, mode=None):
246242
''' work around https://bugs.python.org/issue27777 '''
247243
import tempfile
248-
return tempfile.TemporaryFile("wb+")
244+
if self.length >= 0:
245+
return tempfile.TemporaryFile("wb+")
246+
return super().make_file()
249247

250248
class Client:
251249
"""Instantiate to handle one CGI request.

0 commit comments

Comments
 (0)