Commit 7c734bb2 authored by matt@zope.com's avatar matt@zope.com

Merge lazy object support into REQUEST

parent ed9971a9
......@@ -82,7 +82,7 @@
# attributions are listed in the accompanying credits file.
#
##############################################################################
__version__='$Revision: 1.41 $'[11:-2]
__version__='$Revision: 1.42 $'[11:-2]
from string import join, split, find, rfind, lower, upper
from urllib import quote
......@@ -197,6 +197,9 @@ class BaseRequest:
__getattr__=get=__getitem__
def set_lazy(self, key, callable):
pass # MAYBE, we could do more, but let HTTPRequest do it
def has_key(self,key):
return self.get(key, _marker) is not _marker
......
......@@ -83,7 +83,7 @@
#
##############################################################################
__version__='$Revision: 1.55 $'[11:-2]
__version__='$Revision: 1.56 $'[11:-2]
import re, sys, os, string, urllib, time, whrandom, cgi
from string import lower, atoi, rfind, split, strip, join, upper, find
......@@ -139,7 +139,7 @@ class HTTPRequest(BaseRequest):
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 @@ class HTTPRequest(BaseRequest):
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 @@ class HTTPRequest(BaseRequest):
self.form={}
self.steps=[]
self._steps=[]
self._lazies={}
################################################################
# Get base info first. This isn't likely to cause
......@@ -891,13 +898,26 @@ class HTTPRequest(BaseRequest):
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 @@ class HTTPRequest(BaseRequest):
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 @@ class HTTPRequest(BaseRequest):
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
......@@ -972,6 +996,9 @@ class HTTPRequest(BaseRequest):
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():
if k in ('PARENTS','RESPONSE'): continue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment