[Zope] - keys() and items() for Request objects... and maybe a bug w/ PATH_INFO

Jim Fulton jim@digicool.com
Tue, 22 Dec 1998 14:42:54 +0000


skip@calendar.com wrote:
> 
> I offer the following implementations of keys() and items() for Z Publisher
> Request objects:
> 
>     def keys(self):
>         keys = {}
>         for key in self.environ.keys():
>             if isCGI_NAME(key) or key[:5] == 'HTTP_':
>                 keys[key] = 1
>         keys.update(self.other)
>         lasturl = ""
>         for n in "0123456789":
>             key = "URL%s"%n
>             try:
>                 if lasturl != self[key]:
>                     keys[key] = 1
>                     lasturl = self[key]
>                 else:
>                     break
>             except KeyError:
>                 pass
>         for n in "0123456789":
>             key = "BASE%s"%n
>             try:
>                 if lasturl != self[key]:
>                     keys[key] = 1
>                     lasturl = self[key]
>                 else:
>                     break
>             except KeyError:
>                 pass
>         return keys.keys()
> 
>     def items(self):
>         result = []
>         for k in self.keys():
>             result.append((k, self[k]))
>         return result
> 
> They probably aren't useful in general settings, but are useful for people
> like myself who aren't familiar with what's in a Request and want to explore
> a bit.

I don't want to add this, because I don't want to maintain it.  
If I have a choice between maintaining the above function
(which is incorrect, BTW) and maintaining documentation, I'd
rather maintain documentation.  But if alot of people would
consider the above method useful, I'll reluctantly add (a corrected
version of) it.

> Also, when using this, I discovered what may be a bug.  It's at least a
> feature.   I am using ZopeHTTPServer.  When I examine the REQUEST argument
> of a URL, among other things I find
> 
>     PATH_INFO: '/check_request'
>     PATH_TRANSLATED: '/home/dolphin/skip/src/Zope-1.9.0b3-src/check_request'
>     SCRIPT_NAME: '/'
>     URL: 'http://127.0.0.2:8043/check_request'
> 
> I suppose in a Z Publisher context the distinction between elements of
> PATH_INFO and elements of SCRIPT_NAME is fuzzy, but it seems somehow more
> intuitive to me that I should see
> 
>     PATH_INFO: ''
>     PATH_TRANSLATED: '/home/dolphin/skip/src/Zope-1.9.0b3-src'
>     SCRIPT_NAME: '/check_request'
>     URL: 'http://127.0.0.2:8043/check_request'
> 
> instead.  In a CGI context you always have a non-empty SCRIPT_NAME.  You
> might or might not have a non-empty PATH_INFO.  Given that SCRIPT_NAME and
> PATH_INFO are holdovers from CGI, I think it makes sense to pile everything
> into SCRIPT_NAME and leave PATH_INFO empty.

The script name is the URL up to the name of the application.
PATH_INFO is the part of the URL after the application name
and is used to march into the application.  With ZopeHTTPServer, 
the web server *is* the application, so SCRIPT_NAME must be ''.

Jim

--
Jim Fulton           mailto:jim@digicool.com
Technical Director   (540) 371-6909              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.