RE: [Zope-dev] getting request variables values
Make a DTML method named "req" in your root folder: <dtml-var REQUEST> View it and send the contents to the list.
-----Original Message----- From: Leonardo Kenji Shikida [mailto:kenji@intelligenesis.net] Sent: Thursday, July 20, 2000 4:05 PM To: zope-dev@zope.org Subject: Re: [Zope-dev] getting request variables values
yes, I tryied. both attepts gave me this error:
Error Type: KeyError Error Value: SSL_CLIENT_EMAIL
tips?
Leonardo Kenji Shikida Webmind - Brazil Office
----- Original Message ----- From: Chris McDonough <chrism@digicool.com> To: 'Leonardo Kenji Shikida' <kenji@intelligenesis.net>; <zope-dev@zope.org> Sent: Thursday, July 20, 2000 4:44 PM Subject: RE: [Zope-dev] getting request variables values
Have you tried:
<dtml-var "REQUEST['SSL_CLIENT_EMAIL']">
?
-----Original Message----- From: Leonardo Kenji Shikida [mailto:kenji@intelligenesis.net] Sent: Thursday, July 20, 2000 3:38 PM To: zope-dev@zope.org Subject: Re: [Zope-dev] getting request variables values
that's the point: <dtml-var REQUEST> gives me the value of SSL_CLIENT_EMAIL, that is a HTTPS environment variable but trying to get <dtml-var "REQUEST.SSL_CLIENT_EMAIL"> don't work.
any tips?
Leonardo Kenji Shikida Webmind - Brazil Office
----- Original Message ----- From: Jim Washington <jwashin@vt.edu> To: Leonardo Kenji Shikida <kenji@intelligenesis.net> Sent: Thursday, July 20, 2000 4:18 PM Subject: Re: [Zope-dev] getting request variables values
Leonardo Kenji Shikida wrote:
does not work with
>>>>>>>>>>>>>>>>>>>>> <dtml-var standard_html_header> <h2><dtml-var title_or_id></h2> <dtml-var "REQUEST.SSL_CLIENT_EMAIL"> <dtml-var standard_html_footer> >>>>>>>>>>>>>>>>>>>>>
why?
What does <pre><dtml-var REQUEST></pre> give you?
It will fail if SSL_CLIENT_EMAIL does not have a value (or is bank) in the submitted form.
-- Jim
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
here it is. Kenji
>>>>>
form cookies dtpref_rows 20 dtpref_cols 55 Zope-Version intranet/utility/http%20header%20test tree-s eJyLjlZ3hANPW3UdhWi4iEuEtwWqiKO7j4GteiwYAACvmw8O other tree-s eJyLjlZ3hANPW3UdhWi4iEuEtwWqiKO7j4GteiwYAACvmw8O Zope-Version intranet/utility/http%20header%20test dtpref_rows 20 URL https://snowcrash.intelligenesis.net/pcgi/intranet/utility/http AUTHENTICATED_USER kenji SERVER_URL https://snowcrash.intelligenesis.net dtpref_cols 55 AUTHENTICATION_PATH URL0 https://snowcrash.intelligenesis.net/pcgi/intranet/utility/http URL1 https://snowcrash.intelligenesis.net/pcgi/intranet/utility URL2 https://snowcrash.intelligenesis.net/pcgi/intranet URL3 https://snowcrash.intelligenesis.net/pcgi URL4 https://snowcrash.intelligenesis.net BASE0 https://snowcrash.intelligenesis.net BASE1 https://snowcrash.intelligenesis.net/pcgi BASE2 https://snowcrash.intelligenesis.net/pcgi/intranet BASE3 https://snowcrash.intelligenesis.net/pcgi/intranet/utility BASE4 https://snowcrash.intelligenesis.net/pcgi/intranet/utility/http environ SCRIPT_NAME /pcgi HTTP_ACCEPT_ENCODING gzip, deflate SSL_SERVER_KEY_SIZE 1024 SSL_CLIENT_ISP NY SSL_CLIENT_KEY_EXP SSL_SERVER_CN snowcrash.intelligenesis.net SSL_SERVER_CERT_START Jun 17 06:02:39 2000 GMT SiteRootPATH / SSL_SECRETKEYSIZE 128 GATEWAY_INTERFACE CGI/1.1 SSL_SERVER_OU SSL_CLIENT_CERT_SERIAL 89 SSL_SERVER_IEMAIL helpdesk@intelligenesis.net SSL_SERVER_CERTFILE /usr/local/stronghold/ssl/certs/snowcrash.intelligenesis.net.cert SSL_CLIENT_OU HTTPS on SSL_PROTOCOL_VERSION TLSv1 SSL_SERVER_SIGNATURE_ALGORITHM RSA-MD5 SSL_CLIENT_CN kenji@intelligenesis.net SCRIPT_FILENAME /home/httpd/htdocs/pcgi HTTPS_SECRETKEYSIZE 128 SSL_SERVER_KEY_ALGORITHM rsaEncryption SSL_SERVER_CERTFILETYPE PEM SSL_SERVER_SP New York SSL_CLIENT_IC US SSL_SERVER_IOU IT HTTPS_KEYSIZE 128 SSL_CLIENT_IO Intelligenesis Corporation SSL_CLIENT_IL NY PATH /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin/X11:/u sr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/local/jdk1.2/bin:/root/bin HTTPS_EXPORT false REMOTE_ADDR 200.190.229.61 SSL_CLIENT_IOU IT HTTP_CONNECTION Keep-Alive HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt) SSL_SERVER_SESSIONDIR SSL_SERVER_CERTIFICATELOGDIR SSL_SERVER_KEYFILE /usr/local/stronghold/ssl/private/snowcrash.intelligenesis.net.key SSL_CIPHER RC4-MD5 SSL_CLIENT_IEMAIL helpdesk@intelligenesis.net QUERY_STRING SSL_SERVER_ICN IGC IT CA SERVER_NAME snowcrash.intelligenesis.net PATH_TRANSLATED /home/httpd/htdocs/intranet/utility/http SSL_CLIENT_KEY_SIZE 1024 SSL_CLIENT_CERT_END Jul 19 19:47:52 2002 GMT SSL_CLIENT_CERTIFICATE 320d2bcb.? HTTP_COOKIE tree-s="eJyLjlZ3hANPW3UdhWi4iEuEtwWqiKO7j4GteiwYAACvmw8O"; Zope-Version="intranet/utility/http%20header%20test"; dtpref_rows="20"; dtpref_cols="55" SSL_CLIENT_SIGNATURE_ALGORITHM RSA-MD5 PATH_INFO /intranet/utility/http SSL_SERVER_KEYFILETYPE PEM SSL_SERVER_KEY_EXP SSL_SERVER_IO Intelligenesis Corporation SSL_KEYSIZE 128 SSL_CLIENT_ICN IGC IT CA HTTP_ACCEPT_LANGUAGE en-us SSL_SERVER_C US SSL_SERVER_O Intelligenesis Corporation SSL_SERVER_L New York HTTP_ACCEPT image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/pdf, application/x-comet, */* REQUEST_URI /pcgi/intranet/utility/http SSL_CLIENT_IDN /C=US/ST=NY/L=NY/O=Intelligenesis Corporation/OU=IT/CN=IGC IT CA/Email=helpdesk@intelligenesis.net SSL_SERVER_ISP NY SSL_CLIENT_O Intelligenesis Corporation SSL_CLIENT_L NY SSL_CLIENT_C US HTTP_HOST snowcrash.intelligenesis.net SSL_CLIENT_KEY_ALGORITHM rsaEncryption SERVER_ADMIN intranet@intelligenesis.net SSL_STRONG_CRYPTO true SSL_EXPORT false SSL_SERVER_IDN /C=US/ST=NY/L=NY/O=Intelligenesis Corporation/OU=IT/CN=IGC IT CA/Email=helpdesk@intelligenesis.net DOCUMENT_ROOT /home/httpd/htdocs SSL_SERVER_EMAIL helpdesk@intelligenesis.net SERVER_PORT 443 REMOTE_PORT 62783 SERVER_ROOT /usr/local/stronghold SSL_SERVER_DN /C=US/ST=New York/L=New York/O=Intelligenesis Corporation/CN=snowcrash.intelligenesis.net/Email=helpdesk@intelligenesis.ne t SSL_CLIENT_EMAIL kenji@intelligenesis.net SERVER_PROTOCOL HTTP/1.1 SSL_CLIENT_DN /C=US/ST=NY/L=NY/O=Intelligenesis Corporation/CN=kenji@intelligenesis.net/Email=kenji@intelligenesis.net REQUEST_METHOD GET SERVER_SIGNATURE Stronghold/2.4.2 Apache/1.3.6 C2NetEU/2410 Server at snowcrash.intelligenesis.net Port 443 SSL_SERVER_CERT_SERIAL 0F SERVER_SOFTWARE Stronghold/2.4.2 Apache/1.3.6 C2NetEU/2410 (Unix) (mod_pcgi2/1.0.1; PCGI/2.0a5) ApacheJServ/1.0 SSL_SSLEAY_VERSION SSLeay 0.9.1b.c2eu.4 17-Mar-1999 SSL_SERVER_IC US SSL_CLIENT_CERT_START Jan 26 19:47:52 2000 GMT HTTPS_CIPHER RC4-MD5 SSL_SERVER_CERT_END May 23 06:02:39 2002 GMT SSL_SERVER_IL NY SSL_CLIENT_SP NY HTTP_REFERER https://snowcrash.intelligenesis.net/pcgi/intranet/utility/http/manage_edit Leonardo Kenji Shikida Webmind - Brazil Office
Leonardo Kenji Shikida wrote:
here it is.
Try using <dtml-var "REQUEST['SSLL_CLIENT_IEMAIL']"> instead.
Kenji
>>>>>> SSL_CLIENT_IEMAIL helpdesk@intelligenesis.net
-- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
The value you're after is stored in the 'environ' section of the request. Unlike 'other' and 'cookies' keys, 'environ' keys can't generally be fetched as attributes or keys of REQUEST. You need to access them as REQUEST.environ['keyname']. Cheers, Evan @ digicool & 4-am
Evan Simpson wrote:
The value you're after is stored in the 'environ' section of the request. Unlike 'other' and 'cookies' keys, 'environ' keys can't generally be fetched as attributes or keys of REQUEST. You need to access them as REQUEST.environ['keyname'].
Heh, I thought so, I presume REQUEST.get won't get out of environ either? I posted this in the collector and was told it behaved as expected (and would suck the key out of any of the sub-dictionaries) What's the real story? ;-) cheers, Chris
Chris Withers wrote:
Evan Simpson wrote:
The value you're after is stored in the 'environ' section of the request. Unlike 'other' and 'cookies' keys, 'environ' keys can't generally be fetched as attributes or keys of REQUEST. You need to access them as REQUEST.environ['keyname'].
Heh, I thought so, I presume REQUEST.get won't get out of environ either?
I posted this in the collector and was told it behaved as expected (and would suck the key out of any of the sub-dictionaries)
What's the real story? ;-)
I'm looking at 2.2.0final.
From the comments in the code, it *ought* to look in the environment first.
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. """ However, looking in the code, it starts off by looking in "other", and doesn't look in "environ" at all. I suggest a patch to go right after the method's docstring: def __getitem__(self,key, default=_marker, # Any special internal marker will do URLmatch=regex.compile('URL[0-9]+$').match, BASEmatch=regex.compile('BASE[0-9]+$').match, ): """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. """ #" + environ=self.environ + if environ.has_key(key): + return environ[key] other=self.other if other.has_key(key): if key=='REQUEST': return self return other[key] -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Steve Alexander wrote:
However, looking in the code, it starts off by looking in "other", and doesn't look in "environ" at all.
I suggest a patch to go right after the method's docstring:
def __getitem__(self,key, default=_marker, # Any special internal marker will do URLmatch=regex.compile('URL[0-9]+$').match, BASEmatch=regex.compile('BASE[0-9]+$').match, ): """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.
""" #" + environ=self.environ + if environ.has_key(key): + return environ[key] other=self.other if other.has_key(key): if key=='REQUEST': return self return other[key]
Ok... I was wrong :-/ A bit later we have: 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 '' I was only sort-of wrong though :-) 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: SERVER_SOFTWARE, SERVER_NAME, GATEWAY_INTERFACE, SERVER_PROTOCOL, SERVER_PORT, REQUEST_METHOD, PATH_INFO, PATH_TRANSLATED, SCRIPT_NAME, QUERY_STRING, REMOTE_HOST, REMOTE_ADDR, AUTH_TYPE, REMOTE_USER, REMOTE_IDENT, CONTENT_TYPE, CONTENT_LENGTH, SERVER_URL Looking in Leonardo's sample environment, a posted to this list, there's a lot of keys that won't get matched: SSL_* HTTPS_* REMOTE_PORT SERVER_ROOT SERVER_SIGNATURE My question is "why was __getitem__ of HTTPRequest.py designed this way?". Is there a good reason that it filters the keys according to membership of a standard-cgi-keys list, or whether they start with 'HTTP_' ? Would there be any disadvantage to altering __getitem__ so that it behaves according to its docstring? If so, the patch would probably be something like: line 753. """ #" + 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 '' Comments? -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Steve Alexander wrote:
My question is "why was __getitem__ of HTTPRequest.py designed this way?".
Is there a good reason that it filters the keys according to membership of a standard-cgi-keys list, or whether they start with 'HTTP_' ? Would there be any disadvantage to altering __getitem__ so that it behaves according to its docstring?
...although the class docstring says that the environment variable names are as in the CGI specification (http://hoohoo.ncsa.uiuc.edu/cgi/env.html). It doesn't say that they should **only** be from the CGI specification, though. -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
Steve Alexander wrote:
My question is "why was __getitem__ of HTTPRequest.py designed this way?".
Is there a good reason that it filters the keys according to membership of a standard-cgi-keys list, or whether they start with 'HTTP_' ? Would there be any disadvantage to altering __getitem__ so that it behaves according to its docstring?
I looked at the entire history of that code. This algorithm dates back to 1996. 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. Shane
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 ''
participants (6)
-
Chris McDonough -
Chris Withers -
Evan Simpson -
Leonardo Kenji Shikida -
Shane Hathaway -
Steve Alexander