1.1 --- a/WebStack/Helpers/Request.py Tue Nov 18 20:28:58 2008 +0100
1.2 +++ b/WebStack/Helpers/Request.py Thu Nov 20 21:31:23 2008 +0100
1.3 @@ -225,11 +225,13 @@
1.4
1.5 Instances of this class contain the following attributes:
1.6
1.7 - * stream - a stream object through which the content of an uploaded file
1.8 - may be accessed
1.9 - * content - a plain string containing the contents of the uploaded file
1.10 - * headers - a dictionary containing the headers associated with the
1.11 - uploaded file
1.12 + * stream - a stream object through which the content of an uploaded file
1.13 + may be accessed
1.14 + * content - a plain string containing the contents of the uploaded file
1.15 + * filename - a plain string containing the supplied filename of the
1.16 + uploaded file
1.17 + * headers - a dictionary containing the headers associated with the
1.18 + uploaded file
1.19 """
1.20
1.21 def __init__(self, stream, headers=None):
1.22 @@ -246,20 +248,30 @@
1.23 def __getattr__(self, name):
1.24
1.25 """
1.26 - Provides a property value when 'name' is specified as "content".
1.27 + Provides a property value when 'name' is specified as "content" or as
1.28 + "filename".
1.29 """
1.30
1.31 - if name != "content":
1.32 - raise AttributeError, name
1.33 + if name == "content":
1.34
1.35 - if self.cache is not None:
1.36 - return self.cache
1.37 + if self.cache is not None:
1.38 + return self.cache
1.39
1.40 - if self.reset():
1.41 - return self.stream.read()
1.42 + if self.reset():
1.43 + return self.stream.read()
1.44 + else:
1.45 + self.cache = self.stream.read()
1.46 + return self.cache
1.47 +
1.48 + elif name == "filename":
1.49 + try:
1.50 + content_disposition = self.headers["Content-Disposition"]
1.51 + return content_disposition.filename
1.52 + except (KeyError, AttributeError):
1.53 + return None
1.54 +
1.55 else:
1.56 - self.cache = self.stream.read()
1.57 - return self.cache
1.58 + raise AttributeError, name
1.59
1.60 def reset(self):
1.61