[Zope-Checkins] CVS: Zope/lib/python/ZPublisher - BaseRequest.py:1.44 HTTPRequest.py:1.59
Shane Hathaway
shane@digicool.com
Wed, 19 Dec 2001 10:41:42 -0500
Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv28225
Modified Files:
BaseRequest.py HTTPRequest.py
Log Message:
REQUEST.__getattr__ must raise an AttributeError, not a KeyError, if the
attribute is not found. This change simplifies the signature of get(),
__getitem__(), and __getattr__(), and fixes the bug.
=== Zope/lib/python/ZPublisher/BaseRequest.py 1.43 => 1.44 ===
set=__setitem__
- def __getitem__(self,key,
- default=_marker, # Any special internal marker will do
- ):
+ def get(self, key, default):
"""Get a variable value
Return a value for the required variable name.
@@ -121,9 +119,19 @@
self.other[key]=v
return v
- raise KeyError, key
+ return default
- __getattr__=get=__getitem__
+ def __getitem__(self, key, default=_marker):
+ v = self.get(key, default)
+ if v is _marker:
+ raise KeyError, key
+ return v
+
+ def __getattr__(self, key, default=_marker):
+ v = self.get(key, default)
+ if v is _marker:
+ raise AttributeError, key
+ return v
def set_lazy(self, key, callable):
pass # MAYBE, we could do more, but let HTTPRequest do it
=== Zope/lib/python/ZPublisher/HTTPRequest.py 1.58 => 1.59 ===
return environ.get(name, default)
-
- def __getitem__(self,key,
- default=_marker, # Any special internal marker will do
- URLmatch=re.compile('URL(PATH)?([0-9]+)$').match,
- BASEmatch=re.compile('BASE(PATH)?([0-9]+)$').match,
- ):
+ def get(self, key, default=None,
+ URLmatch=re.compile('URL(PATH)?([0-9]+)$').match,
+ BASEmatch=re.compile('BASE(PATH)?([0-9]+)$').match,
+ ):
"""Get a variable value
Return a value for the required variable name.
@@ -843,17 +841,22 @@
del self._lazies[key]
return v
- if default is not _marker: return default
-
- raise KeyError, key
+ return default
- __getattr__=__getitem__
+ def __getitem__(self, key, default=_marker):
+ v = self.get(key, default)
+ if v is _marker:
+ raise KeyError, key
+ return v
+
+ def __getattr__(self, key, default=_marker):
+ v = self.get(key, default)
+ if v is _marker:
+ raise AttributeError, key
+ return v
def set_lazy(self, key, callable):
self._lazies[key] = callable
-
- def get(self, key, default=None):
- return self.__getitem__(key, default)
def has_key(self, key):
try: self[key]