1.1 --- a/WebStack/Helpers/Request.py Tue Oct 23 23:27:17 2007 +0000
1.2 +++ b/WebStack/Helpers/Request.py Tue Oct 23 23:28:07 2007 +0000
1.3 @@ -58,7 +58,7 @@
1.4 self.length = self.length - len(data)
1.5 return data
1.6
1.7 - def readline(self):
1.8 + def readline(self, n=None):
1.9
1.10 "Reads a single line of data from the message body."
1.11
1.12 @@ -176,20 +176,35 @@
1.13
1.14 Instances of this class contain the following attributes:
1.15
1.16 + * stream - a stream object through which the content of an uploaded file
1.17 + may be accessed
1.18 * content - a plain string containing the contents of the uploaded file
1.19 * headers - a dictionary containing the headers associated with the
1.20 uploaded file
1.21 """
1.22
1.23 - def __init__(self, content, headers=None):
1.24 + def __init__(self, stream, headers=None):
1.25
1.26 """
1.27 - Initialise the object with 'content' and optional 'headers' describing
1.28 - the content.
1.29 + Initialise the object with a 'stream' through which the file can be
1.30 + read, along with optional 'headers' describing the content.
1.31 """
1.32
1.33 - self.content = content
1.34 + self.stream = stream
1.35 self.headers = headers or {}
1.36 + self.cache = None
1.37 +
1.38 + def __getattr__(self, name):
1.39 + if name != "content":
1.40 + raise AttributeError, name
1.41 + if self.cache is not None:
1.42 + return self.cache
1.43 + if hasattr(self.stream, "seek"):
1.44 + self.stream.seek(0)
1.45 + return self.stream.read()
1.46 + else:
1.47 + self.cache = self.stream.read()
1.48 + return self.cache
1.49
1.50 def __str__(self):
1.51 return self.content
1.52 @@ -280,9 +295,9 @@
1.53 # Detect stray FileUpload objects (eg. with Zope).
1.54
1.55 if hasattr(field_value, "read"):
1.56 - return FileContent(field_value.read(), parse_headers(field_value.headers))
1.57 + return FileContent(field_value, parse_headers(field_value.headers))
1.58 else:
1.59 - return FileContent(field_value.value, parse_headers(field_value.headers))
1.60 + return FileContent(field_value.file, parse_headers(field_value.headers))
1.61 else:
1.62 return get_body_field(field_value, encoding)
1.63