# HG changeset patch # User paulb # Date 1193520904 0 # Node ID 4b9e1577bc13815ebdf3dc017eb9f420eb0e8f26 # Parent 4b8a1d2220b151ab5596c17cb68a6fdc90add6c6 [project @ 2007-10-27 21:35:04 by paulb] Added a reset method to the FileContent class. diff -r 4b8a1d2220b1 -r 4b9e1577bc13 WebStack/Helpers/Request.py --- a/WebStack/Helpers/Request.py Sat Oct 27 21:34:37 2007 +0000 +++ b/WebStack/Helpers/Request.py Sat Oct 27 21:35:04 2007 +0000 @@ -195,17 +195,44 @@ self.cache = None def __getattr__(self, name): + + """ + Provides a property value when 'name' is specified as "content". + """ + if name != "content": raise AttributeError, name + if self.cache is not None: return self.cache - if hasattr(self.stream, "seek"): - self.stream.seek(0) + + if self.reset(): return self.stream.read() else: self.cache = self.stream.read() return self.cache + def reset(self): + + "Reset the stream providing the data, returning whether this succeeded." + + # Python file objects. + + if hasattr(self.stream, "seek"): + self.stream.seek(0) + return 1 + + # Java input streams. + + elif hasattr(self.stream, "reset"): + self.stream.reset() + return 1 + + # Other streams. + + else: + return 0 + def __str__(self): return self.content