[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP - IHTTPApplicationResponse.py:1.1.2.2

Jim Fulton jim@zope.com
Mon, 25 Mar 2002 14:05:56 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP
In directory cvs.zope.org:/tmp/cvs-serv24616

Modified Files:
      Tag: Zope3-publisher-refactor-branch
	IHTTPApplicationResponse.py 
Log Message:
Added attributes to get at cookie and header data.

Also added a more specific (than IEnumerableMapping) __getitem__
method that says where the data comes from.

Finally added a potentially controversial URL attribute to get at URL
data.


=== Zope3/lib/python/Zope/Publisher/HTTP/IHTTPApplicationResponse.py 1.1.2.1 => 1.1.2.2 ===
 
 from Zope.Publisher.IApplicationResponse import IApplicationResponse
+from Interface.Attribute import Attribute
 
 
 class IHTTPApplicationResponse(IApplicationResponse):
@@ -24,7 +25,76 @@
     will be used by the application.
     """
 
+    def __getitem__(key):
+        """Return HTTP request data 
+
+        Request data sre retrieved from one of:
+
+        - Environment variables
+
+          These variables include input headers, server data, and other
+          request-related data.  The variable names are as <a
+          href="http://hoohoo.ncsa.uiuc.edu/cgi/env.html">specified</a>
+          in the <a
+          href="http://hoohoo.ncsa.uiuc.edu/cgi/interface.html">CGI
+          specification</a>
+
+        - Cookies
+
+          These are the cookie data, if present.
+
+        Cookies are searched before environmental data.
+        """
+
+    def getCookies():
+        """Return the cookie data
+
+        Data are returned as a mapping object, mapping cookie name to value.
+        """
+
+        return IMapping(str, str)
+
+    cookies = Attribute(
+        """Request cookie data
+
+        This is a read-only mapping from variable name to value.
+        """)
+
+    def getHeader(name, default=None):
+        """Get a header value
+
+        Return the named HTTP header, or an optional default
+        argument or None if the header is not found. Note that
+        both original and CGI-ified header names are recognized,
+        e.g. 'Content-Type', 'CONTENT_TYPE' and 'HTTP_CONTENT_TYPE'
+        should all return the Content-Type header, if available.
+        """
+
+    headers = Attribute(
+        """Request header data
+
+        This is a read-only mapping from variable name to value.
+        """)
+
+    URL = Attribute(
+        """Request URL data
+
+        When convered to a string, this gives the effective published URL.
+
+        This is object can also be used as a mapping object. The keys
+        must be integers or strings that can be converted to
+        integers. A non-negative integer returns a URL n steps from
+        the URL of the top-level application objects. A negative
+        integer gives a URL that is -n steps back from the effective
+        URL.
+
+        For example, 'request.URL[-2]' is equivalent to the Zope 2
+        'request["URL2"]'. The notion is that this would be used in
+        path expressions, like 'request/URL/-2'.
+        """
+
     def redirect(self, location, status=302):
         """Causes a redirection without raising an error.
         """
+