[Zope-dev] getting request variables values

Chris Withers chrisw@nipltd.com
Mon, 24 Jul 2000 19:22:44 +0100


Steve Alexander wrote:
>   def __getitem__/__getattr__ from HTTPRequest.py:
> 
>         """Get a variable value
> 
>         Return a value for the required variable name.
>         The value will be looked up from one of the request data
>         categories. The search order is environment variables,
>         other variables, form data, and then cookies.
> 

Doesn't mention URL parameters on there, does it ;-)
I wonder where they figure in?

> The code certainly doesn't stick exactly to its docstring. The "other"
> dictionary is seached first, then URLx where x is a number.
> Then "environ" is searched, but *only* if the key begins with 'HTTP_' or
> is in the following list:

This looks really messy. I bet it tallies up with what's in the Zope
DTML Reference near the REQUEST description in more ways than with the
docstring...

Shane wrote:
> I think the issue is that environ may include the Zope process
> environment variables, such as PATH, LD_LIBRARY_PATH, CVSROOT, USER,
> etc.  Publish.publish_module() appears to pass in os.environ .  That's
> just a quick analysis, though.

Hurm, there's still the order issue. And that fact that they're visible
if you do <dtml-var REQUEST>.

Wow, should this go in dev.zope.org or the Collector (phrased for
collector, but that can change):

The handling of variable in REQUEST is a bit messy. The following should
all behave the same, in terms of the order variables are searched and
what variables are included:

- <dtml-var REQUEST>

- __getitem__ in HTTPRequest.py

- variables that appear in the DTML/other type of method namespace

Should the patch to HTTPRequest.py below be included into Zope?

         """ #"
 +       environ=self.environ
 +       if environ.has_key(key) and (not hide_key(key)):
 +           return environ[key]
         other=self.other
         if other.has_key(key):
             if key=='REQUEST': return self
             return other[key]

        if key[:1]=='U' and URLmatch(key) >= 0:
            path = self._script + self._steps
            n = len(path) - atoi(key[3:])
            if n < 0:
                raise KeyError, key
            URL=join([other['SERVER_URL']] + path[:n], '/')
            other[key]=URL
            self._urls = self._urls + (key,)
            return URL

-       if isCGI_NAME(key) or key[:5] == 'HTTP_':
-           environ=self.environ
-           if environ.has_key(key) and (not hide_key(key)):
-               return environ[key]
-           return ''