[Zope-Checkins] SVN: Zope/branches/tseaver-fix_wsgi/src/ZPublisher/ Make WSGIResponse.__str__ raise and exception.
Tres Seaver
tseaver at palladion.com
Sat May 29 00:24:53 EDT 2010
Log message for revision 112835:
Make WSGIResponse.__str__ raise and exception.
Prevents an 'attractive nuisance.'
Changed:
U Zope/branches/tseaver-fix_wsgi/src/ZPublisher/WSGIPublisher.py
U Zope/branches/tseaver-fix_wsgi/src/ZPublisher/tests/test_WSGIPublisher.py
-=-
Modified: Zope/branches/tseaver-fix_wsgi/src/ZPublisher/WSGIPublisher.py
===================================================================
--- Zope/branches/tseaver-fix_wsgi/src/ZPublisher/WSGIPublisher.py 2010-05-29 04:24:51 UTC (rev 112834)
+++ Zope/branches/tseaver-fix_wsgi/src/ZPublisher/WSGIPublisher.py 2010-05-29 04:24:52 UTC (rev 112835)
@@ -97,28 +97,15 @@
def __str__(self):
- if self._wrote:
- if self._chunking:
- return '0\r\n\r\n'
- else:
- return ''
+ # XXX Consider how we are to handle the cases this logic was trying
+ # to cover
+ #if self._wrote:
+ # if self._chunking:
+ # return '0\r\n\r\n'
+ # else:
+ # return ''
+ raise NotImplementedError
- chunks = []
- status, headers = self.finalize()
-
- # status header must come first.
- version = self._http_version or '1.0'
- chunks.append("HTTP/%s %s" % (version, status))
-
- for key, val in headers:
- chunks.append("%s: %s" % (key, val))
-
- # RFC 2616 mandates empty line between headers and payload
- chunks.append('')
- chunks.append(self.body)
-
- return "\r\n".join(chunks)
-
def publish(request, module_name, after_list, debug=0):
(bobo_before,
Modified: Zope/branches/tseaver-fix_wsgi/src/ZPublisher/tests/test_WSGIPublisher.py
===================================================================
--- Zope/branches/tseaver-fix_wsgi/src/ZPublisher/tests/test_WSGIPublisher.py 2010-05-29 04:24:51 UTC (rev 112834)
+++ Zope/branches/tseaver-fix_wsgi/src/ZPublisher/tests/test_WSGIPublisher.py 2010-05-29 04:24:52 UTC (rev 112835)
@@ -136,39 +136,24 @@
time.gmtime(time.mktime(WHEN)))
self.failUnless(('Date', whenstr) in headers)
- def test___str__already_wrote_not_chunking(self):
- response = self._makeOne()
- response._wrote = True
- response._chunking = False
- self.assertEqual(str(response), '')
+ #def test___str__already_wrote_not_chunking(self):
+ # response = self._makeOne()
+ # response._wrote = True
+ # response._chunking = False
+ # self.assertEqual(str(response), '')
- def test___str__already_wrote_w_chunking(self):
- response = self._makeOne()
- response._wrote = True
- response._chunking = True
- self.assertEqual(str(response), '0\r\n\r\n')
+ #def test___str__already_wrote_w_chunking(self):
+ # response = self._makeOne()
+ # response._wrote = True
+ # response._chunking = True
+ # self.assertEqual(str(response), '0\r\n\r\n')
- def test___str___w_default_http_version(self):
+ def test___str___raises(self):
response = self._makeOne()
response.setBody('TESTING')
- result = str(response).splitlines()
- self.assertEqual(result[0], 'HTTP/1.0 200 OK')
+ self.assertRaises(NotImplementedError, lambda: str(response))
- def test___str___w_explicit_http_version(self):
- response = self._makeOne()
- response.setBody('TESTING')
- response._http_version = '1.1'
- result = str(response).splitlines()
- self.assertEqual(result[0], 'HTTP/1.1 200 OK')
- def test___str___blankline_before_body(self):
- response = self._makeOne()
- response.setBody('TESTING')
- result = str(response).splitlines()
- self.assertEqual(result[-1], 'TESTING')
- self.assertEqual(result[-2], '')
-
-
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(WSGIResponseTests))
More information about the Zope-Checkins
mailing list