[Zope3-checkins]
SVN: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/
Fixed outstanding failing tests in the publisher. Getting
there, slowly
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Sep 6 23:56:31 EDT 2005
Log message for revision 38334:
Fixed outstanding failing tests in the publisher. Getting there, slowly
but steadily.
Changed:
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/http.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_http.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_publisher.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/xmlrpc.py
-=-
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py 2005-09-07 02:23:52 UTC (rev 38333)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py 2005-09-07 03:56:29 UTC (rev 38334)
@@ -203,15 +203,15 @@
DeprecationWarning,
2)
environ, response, positional = response, positional, outstream
-
-
+
+
self._traversal_stack = []
self._last_obj_traversed = None
self._traversed_names = []
self._environ = environ
self._args = positional or ()
-
+
if response is None:
self._response = self._createResponse()
else:
@@ -444,7 +444,7 @@
DeprecationWarning,
2)
environ, outstream = outstream, environ
-
+
environ['PATH_INFO'] = path
if body_instream is None:
body_instream = StringIO('')
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/http.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/http.py 2005-09-07 02:23:52 UTC (rev 38333)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/http.py 2005-09-07 03:56:29 UTC (rev 38334)
@@ -566,8 +566,8 @@
super(HTTPResponse, self).__init__()
self.reset()
-
+
def reset(self):
'See IResponse'
super(HTTPResponse, self).reset()
@@ -652,7 +652,8 @@
key = '-'.join([k.capitalize() for k in key.split('-')])
result.extend([(key, val) for val in values])
- result.extend([cookie.split(':', 1) for cookie in self._cookie_list()])
+ result.extend([tuple(cookie.split(': ', 1))
+ for cookie in self._cookie_list()])
return result
@@ -718,7 +719,7 @@
# XXX BBB
def _body(self):
- return ''.join(self.result.body)
+ return ''.join(self.result.body)
_body = property(_body)
def _implicitResult(self, body):
@@ -733,8 +734,8 @@
except AttributeError:
raise ValueError(
'Unicode results must have a text content type.')
-
+
major, minor, params = contenttype.parse(content_type)
if 'charset' in params:
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_http.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_http.py 2005-09-07 02:23:52 UTC (rev 38333)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_http.py 2005-09-07 03:56:29 UTC (rev 38334)
@@ -20,7 +20,7 @@
from zope.interface import implements
from zope.publisher.interfaces.logginginfo import ILoggingInfo
-from zope.publisher.http import HTTPRequest, HTTPResponse
+from zope.publisher.http import HTTPRequest, HTTPResponse, StrResult
from zope.publisher.publish import publish
from zope.publisher.base import DefaultPublication
from zope.publisher.interfaces.http import IHTTPRequest, IHTTPResponse
@@ -71,7 +71,7 @@
"""Required docstring for the publisher."""
class Item(object):
- """Required docstring for the publisher."""
+ """Required docstring for the publisher."""
def __call__(self, a, b):
return "%s, %s" % (`a`, `b`)
@@ -444,38 +444,19 @@
response.setBody(body)
return self._parseResult(response)
- def testWrite(self):
- response = self._createResponse()
- data = 'a'*10
- # We have to set all the headers ourself
- response.setHeader('Content-Type', 'text/plain;charset=us-ascii')
- response.setHeader('Content-Length', str(len(data)))
-
- # Stream the data
- for ch in data:
- response.write(ch)
-
- headers, body = self._parseResult(response)
- # Check that the data have been written, and that the header
- # has been preserved
- self.assertEqual(headers['Content-Type'], 'text/plain;charset=us-ascii')
- self.assertEqual(headers['Content-Length'], str(len(data)))
- self.assertEqual(body, data)
-
def testWrite_noContentLength(self):
response = self._createResponse()
- data = 'a'*10
# We have to set all the headers ourself, we choose not to provide a
# content-length header
response.setHeader('Content-Type', 'text/plain;charset=us-ascii')
- # Stream the data
- for ch in data:
- response.write(ch)
+ # Output the data
+ data = 'a'*10
+ response.setResult(StrResult(data))
headers, body = self._parseResult(response)
# Check that the data have been written, and that the header
- # has been preserved
+ # has been preserved
self.assertEqual(headers['Content-Type'], 'text/plain;charset=us-ascii')
self.assertEqual(body, data)
@@ -529,12 +510,10 @@
response = self._createResponse()
for name, value, kw in cookies:
response.setCookie(name, value, **kw)
- response.setBody('test')
- headers, body = self._parseResult(response)
- cookie_headers = headers["Set-Cookie"]
- if type(cookie_headers) != type([]):
- cookie_headers = [cookie_headers]
- return cookie_headers
+ response.setResult('test')
+ return [header[1]
+ for header in response.getHeaders()
+ if header[0] == "Set-Cookie"]
def testSetCookie(self):
c = self._getCookieFromResponse([
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_publisher.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_publisher.py 2005-09-07 02:23:52 UTC (rev 38333)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_publisher.py 2005-09-07 03:56:29 UTC (rev 38334)
@@ -18,7 +18,7 @@
import unittest
from zope.publisher.publish import publish
-from zope.publisher.base import BaseRequest
+from zope.publisher.base import TestRequest
from zope.publisher.base import DefaultPublication
from zope.publisher.interfaces import Unauthorized, NotFound, DebugError
from zope.publisher.interfaces import IPublication
@@ -57,22 +57,20 @@
self.app._item = Item()
self.app.noDocString = NoDocstringItem()
- def _createRequest(self, path, outstream=None, **kw):
- if outstream is None:
- outstream = StringIO()
+ def _createRequest(self, path, **kw):
publication = TestPublication(self.app)
path = path.split('/')
path.reverse()
- request = BaseRequest(StringIO(''), outstream, kw)
+ request = TestRequest(StringIO(''), **kw)
request.setTraversalStack(path)
request.setPublication(publication)
return request
def _publisherResults(self, path, **kw):
- outstream = StringIO()
- request = self._createRequest(path, outstream=outstream, **kw)
- publish(request, handle_errors=0)
- return outstream.getvalue()
+ request = self._createRequest(path, **kw)
+ response = request.response
+ publish(request, handle_errors=False)
+ return response.result
def testImplementsIPublication(self):
self.failUnless(IPublication.providedBy(
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/xmlrpc.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/xmlrpc.py 2005-09-07 02:23:52 UTC (rev 38333)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/xmlrpc.py 2005-09-07 03:56:29 UTC (rev 38334)
@@ -116,24 +116,20 @@
"""Handle Errors during publsihing and wrap it in XML-RPC XML
>>> import sys
- >>> from StringIO import StringIO
- >>> output = StringIO()
- >>> resp = XMLRPCResponse(output)
+ >>> resp = XMLRPCResponse()
>>> try:
... raise AttributeError('xyz')
... except:
... exc_info = sys.exc_info()
... resp.handleException(exc_info)
- ... resp.outputBody()
- ... lines = output.getvalue().split('\\n')
- ... for line in lines:
- ... if 'Status:' in line or 'Content-Type:' in line:
- ... print line.strip()
- ... if '<value><string>' in line:
- ... print line[:61].strip()
- Status: 200 Ok
- Content-Type: text/xml;charset=utf-8
- <value><string>Unexpected Zope exception: AttributeError: xyz
+
+ >>> resp.getStatusString()
+ '200 Ok'
+ >>> resp.getHeader('content-type')
+ 'text/xml;charset=utf-8'
+ >>> body = ''.join(resp.result.body)
+ >>> 'Unexpected Zope exception: AttributeError: xyz' in body
+ True
"""
t, value = exc_info[:2]
s = '%s: %s' % (getattr(t, '__name__', t), value)
@@ -154,7 +150,7 @@
fault_text = Fault(-3, "Unknown Zope fault type")
# Do the damage.
- self.setBody(fault_text)
+ self.setResult(fault_text)
# XML-RPC prefers a status of 200 ("ok") even when reporting errors.
self.setStatus(200)
More information about the Zope3-Checkins
mailing list