[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue 345

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Mar 2 11:35:03 EST 2005


Log message for revision 29382:
  Fixed issue 345
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/doc/TODO.txt
  U   Zope3/trunk/src/zope/publisher/browser.py
  U   Zope3/trunk/src/zope/publisher/tests/test_browserresponse.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-03-02 15:09:47 UTC (rev 29381)
+++ Zope3/trunk/doc/CHANGES.txt	2005-03-02 16:35:03 UTC (rev 29382)
@@ -495,6 +495,9 @@
 
     Bug Fixes
 
+      - Fixed issue #345: Using response.write should not involve unicode 
+                          conversion
+
       - Fixed issue #371: OrderedMultiSelectWidget ignores setRenderedValue
 
       - Fixed issue #360: MultiSelectWidget configured for ISet but creates

Modified: Zope3/trunk/doc/TODO.txt
===================================================================
--- Zope3/trunk/doc/TODO.txt	2005-03-02 15:09:47 UTC (rev 29381)
+++ Zope3/trunk/doc/TODO.txt	2005-03-02 16:35:03 UTC (rev 29382)
@@ -45,6 +45,8 @@
 
   * 363: ftp access with gftp 2.x to the zope x3 ftp server seems broken
 
+  * 375: ftp data channel does not tell control channel about activity 
+
 File Content Component
 ~~~~~~~~~~~~~~~~~~~~~~
 
@@ -74,8 +76,6 @@
 
 * 316: Zope3X test.py truncates path with dir=
 
-* 319: Navigation with anonymous
-
 * 332: Death to IContentContainer
 
 * 334: Failing RuntimeInfo tests 
@@ -86,8 +86,6 @@
 
 * 344: PAU registration error
 
-* 345: Using response.write should not involve unicode conversion
-
 * 356: Copy and Paste does not handle exceptions raised by __setitem__ 
 
 * 369: DAV is hosed on the trunk

Modified: Zope3/trunk/src/zope/publisher/browser.py
===================================================================
--- Zope3/trunk/src/zope/publisher/browser.py	2005-03-02 15:09:47 UTC (rev 29381)
+++ Zope3/trunk/src/zope/publisher/browser.py	2005-03-02 16:35:03 UTC (rev 29382)
@@ -648,6 +648,9 @@
         updates the "content-length" return header and sets the status to
         200 if it has not already been set.
         """
+        if body is None:
+            return
+
         if not isinstance(body, StringTypes):
             body = unicode(body)
 
@@ -666,6 +669,7 @@
         if not self._status_set:
             self.setStatus(200)
 
+
     def __isHTML(self, str):
         """Try to determine whether str is HTML or not."""
         s = str.lstrip().lower()

Modified: Zope3/trunk/src/zope/publisher/tests/test_browserresponse.py
===================================================================
--- Zope3/trunk/src/zope/publisher/tests/test_browserresponse.py	2005-03-02 15:09:47 UTC (rev 29381)
+++ Zope3/trunk/src/zope/publisher/tests/test_browserresponse.py	2005-03-02 16:35:03 UTC (rev 29382)
@@ -82,6 +82,38 @@
             "text/plain")
                      )
 
+    def test_writeDataDirectlyToResponse(self):
+        # In this test we are going to simulate the behavior of a view that
+        # writes its data directly to the output pipe, instead of going
+        # through the entire machinery. This is particularly interesting for
+        # views returning large amount of binary data. 
+        output = StringIO()
+        response = BrowserResponse(output)
+        data = 'My special data.'
+
+        # If you write the data yourself directly, then you are responsible
+        # for setting the status and any other HTTP header yourself as well.
+        response.setHeader('content-type', 'text/plain')
+        response.setHeader('content-length', str(len(data)))
+        response.setStatus(200)
+        
+        # Write the data directly to the output stream from the view
+        response.write(data)
+
+        # Then the view returns `None` and the publisher calls
+        response.setBody(None)
+
+        # Now, if we got here already everything should be fine. The `None`
+        # value for the body should have been ignored and our putput value
+        # should just be our data:
+        self.assertEqual(
+            output.getvalue(),
+            'Status: 200 Ok\r\nContent-Length: 16\r\n'
+            'Content-Type: text/plain;charset=utf-8\r\n'
+            'X-Powered-By: Zope (www.zope.org), Python (www.python.org)\r\n'
+            '\r\n'
+            'My special data.')
+
     def test_interface(self):
         from zope.publisher.interfaces.http import IHTTPResponse
         from zope.publisher.interfaces.http import IHTTPApplicationResponse



More information about the Zope3-Checkins mailing list