Make test_cgi pass. I changed the internal file created by make_file()
to be a text file. (XXX It should use UTF-8 as the encoding.) I also removed the unised 'binary' argument from the make_file() signature. XXX I am under no illusion that this is now working; I're pretty sure it would be more principled if it always read binary data. But that's for someone who actually cares about this module.
This commit is contained in:
parent
0cb431c071
commit
a1a68521db
20
Lib/cgi.py
20
Lib/cgi.py
|
@ -662,7 +662,7 @@ class FieldStorage:
|
||||||
|
|
||||||
def read_binary(self):
|
def read_binary(self):
|
||||||
"""Internal: read binary data."""
|
"""Internal: read binary data."""
|
||||||
self.file = self.make_file('b')
|
self.file = self.make_file()
|
||||||
todo = self.length
|
todo = self.length
|
||||||
if todo >= 0:
|
if todo >= 0:
|
||||||
while todo > 0:
|
while todo > 0:
|
||||||
|
@ -684,8 +684,9 @@ class FieldStorage:
|
||||||
def __write(self, line):
|
def __write(self, line):
|
||||||
if self.__file is not None:
|
if self.__file is not None:
|
||||||
if self.__file.tell() + len(line) > 1000:
|
if self.__file.tell() + len(line) > 1000:
|
||||||
self.file = self.make_file('')
|
self.file = self.make_file()
|
||||||
self.file.write(self.__file.getvalue())
|
data = self.__file.getvalue()
|
||||||
|
self.file.write(data)
|
||||||
self.__file = None
|
self.__file = None
|
||||||
self.file.write(line)
|
self.file.write(line)
|
||||||
|
|
||||||
|
@ -751,7 +752,7 @@ class FieldStorage:
|
||||||
break
|
break
|
||||||
last_line_lfend = line.endswith('\n')
|
last_line_lfend = line.endswith('\n')
|
||||||
|
|
||||||
def make_file(self, binary=None):
|
def make_file(self):
|
||||||
"""Overridable: return a readable & writable file.
|
"""Overridable: return a readable & writable file.
|
||||||
|
|
||||||
The file will be used as follows:
|
The file will be used as follows:
|
||||||
|
@ -759,8 +760,7 @@ class FieldStorage:
|
||||||
- seek(0)
|
- seek(0)
|
||||||
- data is read from it
|
- data is read from it
|
||||||
|
|
||||||
The 'binary' argument is unused -- the file is always opened
|
The file is always opened in text mode.
|
||||||
in binary mode.
|
|
||||||
|
|
||||||
This version opens a temporary file for reading and writing,
|
This version opens a temporary file for reading and writing,
|
||||||
and immediately deletes (unlinks) it. The trick (on Unix!) is
|
and immediately deletes (unlinks) it. The trick (on Unix!) is
|
||||||
|
@ -776,7 +776,7 @@ class FieldStorage:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import tempfile
|
import tempfile
|
||||||
return tempfile.TemporaryFile("w+b")
|
return tempfile.TemporaryFile("w+")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -946,8 +946,7 @@ def print_exception(type=None, value=None, tb=None, limit=None):
|
||||||
|
|
||||||
def print_environ(environ=os.environ):
|
def print_environ(environ=os.environ):
|
||||||
"""Dump the shell environment as HTML."""
|
"""Dump the shell environment as HTML."""
|
||||||
keys = environ.keys()
|
keys = sorted(environ.keys())
|
||||||
keys.sort()
|
|
||||||
print()
|
print()
|
||||||
print("<H3>Shell Environment:</H3>")
|
print("<H3>Shell Environment:</H3>")
|
||||||
print("<DL>")
|
print("<DL>")
|
||||||
|
@ -958,8 +957,7 @@ def print_environ(environ=os.environ):
|
||||||
|
|
||||||
def print_form(form):
|
def print_form(form):
|
||||||
"""Dump the contents of a form as HTML."""
|
"""Dump the contents of a form as HTML."""
|
||||||
keys = form.keys()
|
keys = sorted(form.keys())
|
||||||
keys.sort()
|
|
||||||
print()
|
print()
|
||||||
print("<H3>Form Contents:</H3>")
|
print("<H3>Form Contents:</H3>")
|
||||||
if not keys:
|
if not keys:
|
||||||
|
|
|
@ -231,8 +231,8 @@ class CgiTests(unittest.TestCase):
|
||||||
setattr(self, name, a)
|
setattr(self, name, a)
|
||||||
return a
|
return a
|
||||||
|
|
||||||
f = TestReadlineFile(tempfile.TemporaryFile())
|
f = TestReadlineFile(tempfile.TemporaryFile("w+"))
|
||||||
f.write(b'x' * 256 * 1024)
|
f.write('x' * 256 * 1024)
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
env = {'REQUEST_METHOD':'PUT'}
|
env = {'REQUEST_METHOD':'PUT'}
|
||||||
fs = cgi.FieldStorage(fp=f, environ=env)
|
fs = cgi.FieldStorage(fp=f, environ=env)
|
||||||
|
|
Loading…
Reference in New Issue