[Zope3-checkins]
SVN: Zope3/branches/stephan_and_jim-response-refactor/src/zope/
Made Response.result a private attribute: Response._result.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Sep 7 14:38:10 EDT 2005
Log message for revision 38351:
Made Response.result a private attribute: Response._result.
For HTTPResponse provide consumeBody and consumeBodyIter. This made the
API more sane.
Changed:
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/dav/tests/test_propfind.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/dav/tests/test_proppatch.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_browserpublication.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_zopepublication.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/testing/functional.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/wsgi/__init__.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/browser.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/ftp.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/interfaces/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
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/publisherhttpserver.py
U Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/tests/test_wsgiserver.py
-=-
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/dav/tests/test_propfind.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/dav/tests/test_propfind.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/dav/tests/test_propfind.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -267,7 +267,7 @@
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
self.assertEqual(pfind.getDepth(), depth)
- s1 = normalize_xml(''.join(request.response.result.body))
+ s1 = normalize_xml(request.response.consumeBody())
s2 = normalize_xml(expect)
self.assertEqual(s1, s2)
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/dav/tests/test_proppatch.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/dav/tests/test_proppatch.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/dav/tests/test_proppatch.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -246,7 +246,7 @@
ppatch.PROPPATCH()
# Check HTTP Response
self.assertEqual(request.response.getStatus(), 207)
- s1 = normalize_xml(''.join(request.response.result.body))
+ s1 = normalize_xml(request.response.consumeBody())
s2 = normalize_xml(expect)
self.assertEqual(s1, s2)
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_browserpublication.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_browserpublication.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_browserpublication.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -260,7 +260,7 @@
request.setPrincipal(User())
request.response.setResult(u"spam")
pub.afterCall(request, None)
- self.assertEqual(request.response.testBody(), 'spam' )
+ self.assertEqual(request.response.consumeBody(), 'spam' )
# But with a HEAD request, the body should be empty
request = TestRequest(StringIO(''), {'PATH_INFO': '/'})
@@ -268,7 +268,7 @@
request.method = 'HEAD'
request.response.setResult(u"spam")
pub.afterCall(request, None)
- self.assertEqual(request.response.testBody(), '')
+ self.assertEqual(request.response.consumeBody(), '')
def testUnicode_NO_HTTP_CHARSET(self):
# Test so that a unicode body doesn't cause a UnicodeEncodeError
@@ -283,7 +283,7 @@
('X-Content-Type-Warning', 'guessed from content'),
('X-Powered-By', 'Zope (www.zope.org), Python (www.python.org)')])
self.assertEqual(
- ''.join(request.response.result.body),
+ request.response.consumeBody(),
'\xd1\x82\xd0\xb5\xd1\x81\xd1\x82')
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_zopepublication.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/publication/tests/test_zopepublication.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -31,7 +31,6 @@
from zope.publisher.base import TestPublication, TestRequest
from zope.publisher.http import IHTTPRequest, HTTPCharsets
from zope.publisher.interfaces import IRequest, IPublishTraverse
-from zope.publisher.browser import BrowserResponse
from zope.security import simplepolicies
from zope.security.management import setSecurityPolicy, queryInteraction
from zope.security.management import endInteraction
@@ -168,7 +167,7 @@
pass
self.publication.handleException(
self.object, self.request, sys.exc_info(), retry_allowed=False)
- value = ''.join(self.request.response.result).split()
+ value = ''.join(self.request.response._result).split()
self.assertEqual(' '.join(value[:6]),
'Traceback (most recent call last): File')
self.assertEqual(' '.join(value[-8:]),
@@ -192,7 +191,7 @@
pass
self.publication.handleException(
self.object, self.request, sys.exc_info(), retry_allowed=False)
- self.assertEqual(''.join(self.request.response.result), view_text)
+ self.assertEqual(self.request.response._result, view_text)
def testHandlingSystemErrors(self):
@@ -257,7 +256,7 @@
'SiteError ERROR\n'
' http://test.url'
)
-
+
handler.uninstall()
def testNoViewOnClassicClassException(self):
@@ -279,9 +278,9 @@
self.publication.handleException(
self.object, self.request, sys.exc_info(), retry_allowed=False)
# check we don't get the view we registered
- self.failIf(''.join(self.request.response.result) == view_text)
+ self.failIf(''.join(self.request.response._result) == view_text)
# check we do actually get something
- self.failIf(''.join(self.request.response.result) == '')
+ self.failIf(''.join(self.request.response._result) == '')
def testExceptionSideEffects(self):
from zope.publisher.interfaces import IExceptionSideEffects
@@ -389,23 +388,22 @@
f1['f2'] = Folder()
sm1 = setup.createSiteManager(f1)
setup.addUtility(sm1, '', IAuthenticationUtility, AuthUtility1())
-
+
f2 = f1['f2']
sm2 = setup.createSiteManager(f2)
setup.addUtility(sm2, '', IAuthenticationUtility, AuthUtility2())
transaction.commit()
-
-
+
from zope.app.container.interfaces import ISimpleReadContainer
from zope.app.container.traversal import ContainerTraverser
-
+
ztapi.provideView(ISimpleReadContainer, IRequest, IPublishTraverse,
'', ContainerTraverser)
-
+
from zope.app.folder.interfaces import IFolder
from zope.security.checker import defineChecker, InterfaceChecker
defineChecker(Folder, InterfaceChecker(IFolder))
-
+
self.publication.beforeTraversal(self.request)
self.assertEqual(list(queryInteraction().participations),
[self.request])
@@ -422,7 +420,7 @@
self.assertEqual(list(queryInteraction().participations),
[self.request])
self.publication.endRequest(self.request, ob)
- self.assertEqual(queryInteraction(), None)
+ self.assertEqual(queryInteraction(), None)
def testTransactionCommitAfterCall(self):
root = self.db.open().root()
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/testing/functional.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/testing/functional.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/testing/functional.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -84,7 +84,7 @@
def getBody(self):
"""Returns the response body"""
if self._body is None:
- self._body = ''.join(self._response.result.body)
+ self._body = ''.join(self._response.consumeBody())
return self._body
@@ -473,7 +473,7 @@
def testLinks(self):
response = self.publish('/')
self.assertEquals(response.getStatus(), 200)
- self.checkForBrokenLinks(response.getBody(), response.getPath())
+ self.checkForBrokenLinks(response.consumeBody(), response.getPath())
def sample_test_suite():
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/wsgi/__init__.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/wsgi/__init__.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/app/wsgi/__init__.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -52,4 +52,4 @@
start_response(response.getStatusString(), response.getHeaders())
# Return the result body iterable.
- return response.result.body
+ return response.consumeBodyIter()
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 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/base.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -37,7 +37,7 @@
"""
__slots__ = (
- 'result', # The result of the application call
+ '_result', # The result of the application call
'_request', # The associated request (if any)
)
@@ -56,7 +56,7 @@
def setResult(self, result):
'See IPublisherResponse'
- self.result = result
+ self._result = result
def handleException(self, exc_info):
'See IPublisherResponse'
@@ -472,7 +472,7 @@
warnings.warn("Can't pass output streams to requests anymore",
DeprecationWarning,
2)
- self._outstream.write(self.result)
+ self._outstream.write(self._result)
class DefaultPublication(object):
"""A stub publication.
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/browser.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/browser.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/browser.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -729,9 +729,6 @@
class BBBResponse(BrowserResponse):
- def testBody(self):
- return ''.join(self.result.body)
-
def outputBody(self):
import warnings
warnings.warn("Can't pass output streams to requests anymore",
@@ -744,7 +741,7 @@
"\r\n".join([("%s: %s" % h) for h in headers])
+ "\r\n\r\n"
)
- self.outstream.write(''.join(self.result.body))
+ self.outstream.write(''.join(self.getBody()))
def isHTML(str):
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/ftp.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/ftp.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/ftp.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -29,7 +29,7 @@
def getResult(self):
if getattr(self, '_exc', None) is not None:
raise self._exc[0], self._exc[1], self._exc[2]
- return self.result
+ return self._result
def handleException(self, exc_info):
self._exc = exc_info
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 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/http.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -736,18 +736,30 @@
r = DirectResult((body,), headers)
else:
raise TypeError('The result should be adaptable to IResult.')
- self.result = r
+ self._result = r
self._headers.update(dict([(k, [v]) for (k, v) in r.headers]))
if not self._status_set:
self.setStatus(200)
+
+ def consumeBody(self):
+ 'See IHTTPResponse'
+ return ''.join(self._result.body)
+
+
+ def consumeBodyIter(self):
+ 'See IHTTPResponse'
+ return self._result.body
+
+
# BBB: Backward-compatibility for old body API
- _body = property(lambda self: ''.join(self.result.body))
+ _body = property(consumeBody)
_body = deprecation.deprecated(
_body,
- '`_body` has been deprecated in favor of `result`. '
+ '`_body` has been deprecated in favor of `consumeBody()`. '
'This will go away in Zope 3.4.')
+
def _implicitResult(self, body):
encoding = getCharsetUsingRequest(self._request) or 'utf-8'
content_type = self.getHeader('content-type')
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/interfaces/http.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/interfaces/http.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/interfaces/http.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -371,7 +371,21 @@
"""Sets the response result value that is adaptable to ``IResult``.
"""
+ def consumeBody():
+ """Returns the response body as a string.
+ Note that this function can be only requested once, since it is
+ constructed from the result.
+ """
+
+ def consumeBodyIter():
+ """Returns the response body as an iterable.
+
+ Note that this function can be only requested once, since it is
+ constructed from the result.
+ """
+
+
class IResult(Interface):
"""HTTP result.
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 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_http.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -103,7 +103,7 @@
+
"\r\n".join([("%s: %s" % h) for h in headers]) + "\r\n\r\n"
+
- ''.join(response.result.body)
+ ''.join(response.consumeBody())
)
def test_repr(self):
@@ -425,7 +425,7 @@
return response
def _parseResult(self, response):
- return dict(response.getHeaders()), ''.join(response.result.body)
+ return dict(response.getHeaders()), ''.join(response.consumeBody())
def _getResultFromResponse(self, body, charset='utf-8', headers=None):
response = self._createResponse()
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 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/tests/test_publisher.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -70,7 +70,7 @@
request = self._createRequest(path, **kw)
response = request.response
publish(request, handle_errors=False)
- return response.result
+ 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 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/publisher/xmlrpc.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -127,7 +127,7 @@
'200 Ok'
>>> resp.getHeader('content-type')
'text/xml;charset=utf-8'
- >>> body = ''.join(resp.result.body)
+ >>> body = ''.join(resp.consumeBody())
>>> 'Unexpected Zope exception: AttributeError: xyz' in body
True
"""
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/publisherhttpserver.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/publisherhttpserver.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/publisherhttpserver.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -30,7 +30,7 @@
request = publish(request)
response = request.response
start_response(response.getStatusString(), response.getHeaders())
- return response.result.body
+ return response.consumeBody()
return super(PublisherHTTPServer, self).__init__(
application, sub_protocol, *args, **kw)
@@ -57,7 +57,7 @@
response = request.response
start_response(response.getStatusString(), response.getHeaders())
- return response.result.body
+ return response.consumeBody()
return super(PublisherHTTPServer, self).__init__(
application, sub_protocol, *args, **kw)
Modified: Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/tests/test_wsgiserver.py
===================================================================
--- Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/tests/test_wsgiserver.py 2005-09-07 18:37:48 UTC (rev 38350)
+++ Zope3/branches/stephan_and_jim-response-refactor/src/zope/server/http/tests/test_wsgiserver.py 2005-09-07 18:38:10 UTC (rev 38351)
@@ -107,7 +107,7 @@
request = publish(request)
response = request.response
start_response(response.getStatusString(), response.getHeaders())
- return response.result.body
+ return response.consumeBody()
td.setThreadCount(4)
# Bind to any port on localhost.
More information about the Zope3-Checkins
mailing list