def read_binary(self):
"""Internal: read binary data."""
- self.file = self.make_file('b')
+ self.file = self.make_file()
todo = self.length
if todo >= 0:
while todo > 0:
def __write(self, line):
if self.__file is not None:
if self.__file.tell() + len(line) > 1000:
- self.file = self.make_file('')
- self.file.write(self.__file.getvalue())
+ self.file = self.make_file()
+ data = self.__file.getvalue()
+ self.file.write(data)
self.__file = None
self.file.write(line)
break
last_line_lfend = line.endswith('\n')
- def make_file(self, binary=None):
+ def make_file(self):
"""Overridable: return a readable & writable file.
The file will be used as follows:
- seek(0)
- data is read from it
- The 'binary' argument is unused -- the file is always opened
- in binary mode.
+ The file is always opened in text mode.
This version opens a temporary file for reading and writing,
and immediately deletes (unlinks) it. The trick (on Unix!) is
"""
import tempfile
- return tempfile.TemporaryFile("w+b")
+ return tempfile.TemporaryFile("w+")
def print_environ(environ=os.environ):
"""Dump the shell environment as HTML."""
- keys = environ.keys()
- keys.sort()
+ keys = sorted(environ.keys())
print()
print("<H3>Shell Environment:</H3>")
print("<DL>")
def print_form(form):
"""Dump the contents of a form as HTML."""
- keys = form.keys()
- keys.sort()
+ keys = sorted(form.keys())
print()
print("<H3>Form Contents:</H3>")
if not keys:
setattr(self, name, a)
return a
- f = TestReadlineFile(tempfile.TemporaryFile())
- f.write(b'x' * 256 * 1024)
+ f = TestReadlineFile(tempfile.TemporaryFile("w+"))
+ f.write('x' * 256 * 1024)
f.seek(0)
env = {'REQUEST_METHOD':'PUT'}
fs = cgi.FieldStorage(fp=f, environ=env)