[Repoze-checkins] r1076 - repoze.zope2/trunk/repoze/zope2

Chris McDonough chrism at agendaless.com
Wed Jun 11 21:58:33 EDT 2008


Author: Chris McDonough <chrism at agendaless.com>
Date: Wed Jun 11 21:58:32 2008
New Revision: 1076

Log:
Refactor map_result slightly (it was 2 buffers long).


Modified:
   repoze.zope2/trunk/repoze/zope2/z2bob.py

Modified: repoze.zope2/trunk/repoze/zope2/z2bob.py
==============================================================================
--- repoze.zope2/trunk/repoze/zope2/z2bob.py	(original)
+++ repoze.zope2/trunk/repoze/zope2/z2bob.py	Wed Jun 11 21:58:32 2008
@@ -431,13 +431,6 @@
             response.stdout.seek(0)
             result = response.stdout
 
-        status = response.headers.get('status')
-        if status is None:
-            code, reason = convertResponseCode(response.status)
-            status = '%d %s' % (code, reason)
-        else:
-            del response.headers['status']
-
         if result is response:
             result = response.body
 
@@ -450,7 +443,6 @@
 
         if result is None:
             result = ''
-
         if isinstance(result, bool):
             result = str(result)
         if isinstance(result, unicode):
@@ -495,12 +487,15 @@
             ct = '%s; charset=%s' % (ct, self.encoding)
             response.setHeader('content-type', ct)
 
-        cookies = [ ('set-cookie', cookie) for cookie in self._getCookies() ]
-        cookies.sort()
-        headers = response.headers.items()
-        headers.sort()
-        headers = headers + cookies
-        httpheaders.normalize_headers(headers, strict=False)
+        status = response.headers.get('status')
+        if status is None:
+            code, reason = convertResponseCode(response.status)
+            status = '%d %s' % (code, reason)
+        else:
+            # this should not be in the headers list
+            del response.headers['status']
+
+        headers = self._getResponseHeaders()
         return status, headers, result
 
     def handle_exception(self, exc_info):
@@ -508,7 +503,7 @@
         try:
             if ((t == 'Unauthorized') or
                 (inspect.isclass(t) and issubclass(t, _UNAUTH_CLASSES))):
-                response = self.request.RESPONSE
+                response = self.request.response
                 response._unauthorized()
                 response.setStatus(401)
                 val = str(v)
@@ -524,15 +519,10 @@
 
     # helper methods
 
-    def _getCookies(self):
+    def _getResponseHeaders(self):
         response = self.request.response
         cookie_list = []
         for name, attrs in response.cookies.items():
-
-            # Note that as of May 98, IE4 ignores cookies with
-            # quoted cookie attr values, so only the value part
-            # of name=value pairs may be quoted.
-
             cookie = '%s="%s"' % (name, attrs['value'])
             for name, v in attrs.items():
                 name = name.lower()
@@ -550,9 +540,13 @@
                     cookie = '%s; Secure' % cookie
             cookie_list.append(cookie)
 
-        # Should really check size of cookies here!
-
-        return cookie_list
+        cookies = [ ('set-cookie', cookie) for cookie in cookie_list ]
+        cookies.sort()
+        headers = response.headers.items()
+        headers.sort()
+        headers = headers + cookies
+        httpheaders.normalize_headers(headers, strict=False)
+        return headers
 
     def _get_user(self):
         user = None


More information about the Repoze-checkins mailing list