[Zope-Checkins] CVS: Zope/lib/python/ZPublisher - HTTPRequest.py:1.55.34.1
Matthew T. Kromer
matt@zope.com
Tue, 6 Nov 2001 16:06:28 -0500
Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv19356
Modified Files:
Tag: matt-Transience-branch
HTTPRequest.py
Log Message:
Add lazy objects to HTTPrequest
=== Zope/lib/python/ZPublisher/HTTPRequest.py 1.55 => 1.55.34.1 ===
The request object is a mapping object that represents a
collection of variable to value mappings. In addition, variables
- are divided into four categories:
+ are divided into five categories:
- Environment variables
@@ -159,6 +159,12 @@
These are the cookie data, if present.
+ - Lazy Data
+
+ These are callables which are deferred until explicitly
+ referenced, at which point they are resolved and stored as
+ application data.
+
- Other
Data that may be set by an application object.
@@ -304,6 +310,7 @@
self.form={}
self.steps=[]
self._steps=[]
+ self._lazies={}
################################################################
# Get base info first. This isn't likely to cause
@@ -891,13 +898,26 @@
self.other[key]=v
return v
- v=self.common.get(key, default)
+ v=self.common.get(key, _marker)
if v is not _marker: return v
+ if self._lazies:
+ v = self._lazies.get(key, _marker)
+ if v is not _marker:
+ if callable(v): v = v()
+ self[key] = v # Promote lazy value
+ del self._lazies[key]
+ return v
+
+ if default is not _marker: return default
+
raise KeyError, key
__getattr__=__getitem__
+ def set_lazy(self, key, callable):
+ self._lazies[key] = callable
+
def get(self, key, default=None):
return self.__getitem__(key, default)
@@ -909,6 +929,7 @@
def keys(self):
keys = {}
keys.update(self.common)
+ keys.update(self._lazies)
for key in self.environ.keys():
if (isCGI_NAME(key) or key[:5] == 'HTTP_') and \
@@ -942,6 +963,9 @@
result=result+"</table><h3>cookies</h3><table>"
for k,v in self.cookies.items():
result=result + row % (escape(k), escape(repr(v)))
+ result=result+"</table><h3>lazy items</h3><table>"
+ for k,v in self._lazies.items():
+ result=result + row % (escape(k), escape(repr(v)))
result=result+"</table><h3>other</h3><table>"
for k,v in self.other.items():
if k in ('PARENTS','RESPONSE'): continue
@@ -971,6 +995,9 @@
result=result + row % (k, repr(v))
result=result+"\nCOOKIES\n\n"
for k,v in self.cookies.items():
+ result=result + row % (k, repr(v))
+ result=result+"\nLAZY ITEMS\n\n"
+ for k,v in self._lazies.items():
result=result + row % (k, repr(v))
result=result+"\nOTHER\n\n"
for k,v in self.other.items():