[Zope3-checkins] SVN: Zope3/branches/3.2/src/zope/server/ I previously changed the channel write method to accept iterables.

Jim Fulton jim at zope.com
Sat Dec 31 14:59:24 EST 2005


Log message for revision 41059:
  I previously changed the channel write method to accept iterables.
  Nowe changed the write method to return the number of bytes written,
  as the HTTP server needs this for logging.
  

Changed:
  U   Zope3/branches/3.2/src/zope/server/dualmodechannel.py
  U   Zope3/branches/3.2/src/zope/server/ftp/server.py
  U   Zope3/branches/3.2/src/zope/server/http/httptask.py
  U   Zope3/branches/3.2/src/zope/server/tests/test_serverbase.py

-=-
Modified: Zope3/branches/3.2/src/zope/server/dualmodechannel.py
===================================================================
--- Zope3/branches/3.2/src/zope/server/dualmodechannel.py	2005-12-31 19:29:21 UTC (rev 41058)
+++ Zope3/branches/3.2/src/zope/server/dualmodechannel.py	2005-12-31 19:59:24 UTC (rev 41059)
@@ -152,13 +152,16 @@
     #
 
     def write(self, data):
+        wrote = 0
         if isinstance(data, str):
             if data:
                 self.outbuf.append(data)
+                wrote = len(data) 
         else:
             for v in data:
                 if v:
                     self.outbuf.append(v)
+                    wrote += len(v)
 
         while len(self.outbuf) >= self.adj.send_bytes:
             # Send what we can without blocking.
@@ -167,6 +170,8 @@
             if not self._flush_some():
                 break
 
+        return wrote
+
     def pull_trigger(self):
         """Wakes up the main loop.
         """

Modified: Zope3/branches/3.2/src/zope/server/ftp/server.py
===================================================================
--- Zope3/branches/3.2/src/zope/server/ftp/server.py	2005-12-31 19:29:21 UTC (rev 41058)
+++ Zope3/branches/3.2/src/zope/server/ftp/server.py	2005-12-31 19:59:24 UTC (rev 41059)
@@ -899,7 +899,7 @@
             raise IOError('Client FTP connection closed')
         if not self.opened:
             self._open()
-        FTPDataChannel.write(self, data)
+        return FTPDataChannel.write(self, data)
 
     def readable(self):
         return not self.connected

Modified: Zope3/branches/3.2/src/zope/server/http/httptask.py
===================================================================
--- Zope3/branches/3.2/src/zope/server/http/httptask.py	2005-12-31 19:29:21 UTC (rev 41058)
+++ Zope3/branches/3.2/src/zope/server/http/httptask.py	2005-12-31 19:59:24 UTC (rev 41059)
@@ -229,8 +229,7 @@
             self.bytes_written += len(rh)
             self.wrote_header = 1
         if data:
-            channel.write(data)
-            self.bytes_written += len(data)
+            self.bytes_written += channel.write(data)
 
     def flush(self):
         self.channel.flush()

Modified: Zope3/branches/3.2/src/zope/server/tests/test_serverbase.py
===================================================================
--- Zope3/branches/3.2/src/zope/server/tests/test_serverbase.py	2005-12-31 19:29:21 UTC (rev 41058)
+++ Zope3/branches/3.2/src/zope/server/tests/test_serverbase.py	2005-12-31 19:59:24 UTC (rev 41059)
@@ -58,12 +58,16 @@
     >>> socket = FakeSocket()
     >>> channel = DualModeChannel(socket, ('localhost', 42))
 
-    >> channel.write("First")
-    >> channel.flush()
-    >> print socket.data
+    >>> channel.write("First")
+    5
+    
+    >>> channel.flush()
+    >>> print socket.data
     First
 
-    >>> channel.write(["First", "\n", "Second", "\n", "Third"])
+    >>> channel.write(["\n", "Second", "\n", "Third"])
+    13
+    
     >>> channel.flush()
     >>> print socket.data
     First
@@ -75,6 +79,8 @@
     ...     yield 'I love to count. Ha ha ha.'
 
     >>> channel.write(count())
+    33
+    
     >>> channel.flush()
     >>> print socket.data
     First



More information about the Zope3-Checkins mailing list