Commit 7a8cf472 authored by Shane Hathaway's avatar Shane Hathaway

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.
parent c251b8f6
......@@ -10,7 +10,7 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__version__='$Revision: 1.43 $'[11:-2]
__version__='$Revision: 1.44 $'[11:-2]
from string import join, split, find, rfind, lower, upper
from urllib import quote
......@@ -90,9 +90,7 @@ class BaseRequest:
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 @@ class BaseRequest:
self.other[key]=v
return v
raise KeyError, key
__getattr__=get=__getitem__
return default
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
......
......@@ -11,7 +11,7 @@
#
##############################################################################
__version__='$Revision: 1.58 $'[11:-2]
__version__='$Revision: 1.59 $'[11:-2]
import re, sys, os, string, urllib, time, whrandom, cgi
from string import lower, atoi, rfind, split, strip, join, upper, find
......@@ -754,12 +754,10 @@ class HTTPRequest(BaseRequest):
name='HTTP_%s' % name
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,18 +841,23 @@ class HTTPRequest(BaseRequest):
del self._lazies[key]
return v
if default is not _marker: return default
return default
raise KeyError, key
def __getitem__(self, key, default=_marker):
v = self.get(key, default)
if v is _marker:
raise KeyError, key
return v
__getattr__=__getitem__
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]
except: return 0
......
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