[Zope3-checkins] SVN: Zope3/trunk/src/zope/server/ Merged from 3.2 branch:

Jim Fulton jim at zope.com
Tue Jan 3 14:02:50 EST 2006


Log message for revision 41111:
  Merged from 3.2 branch:
  
  r41059 | jim | 2005-12-31 14:59:24 -0500 (Sat, 31 Dec 2005) | 4 lines
  
  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/trunk/src/zope/server/dualmodechannel.py
  U   Zope3/trunk/src/zope/server/ftp/server.py
  U   Zope3/trunk/src/zope/server/http/httptask.py
  U   Zope3/trunk/src/zope/server/tests/test_serverbase.py

-=-
Modified: Zope3/trunk/src/zope/server/dualmodechannel.py
===================================================================
--- Zope3/trunk/src/zope/server/dualmodechannel.py	2006-01-03 19:01:56 UTC (rev 41110)
+++ Zope3/trunk/src/zope/server/dualmodechannel.py	2006-01-03 19:02:50 UTC (rev 41111)
@@ -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/trunk/src/zope/server/ftp/server.py
===================================================================
--- Zope3/trunk/src/zope/server/ftp/server.py	2006-01-03 19:01:56 UTC (rev 41110)
+++ Zope3/trunk/src/zope/server/ftp/server.py	2006-01-03 19:02:50 UTC (rev 41111)
@@ -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/trunk/src/zope/server/http/httptask.py
===================================================================
--- Zope3/trunk/src/zope/server/http/httptask.py	2006-01-03 19:01:56 UTC (rev 41110)
+++ Zope3/trunk/src/zope/server/http/httptask.py	2006-01-03 19:02:50 UTC (rev 41111)
@@ -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/trunk/src/zope/server/tests/test_serverbase.py
===================================================================
--- Zope3/trunk/src/zope/server/tests/test_serverbase.py	2006-01-03 19:01:56 UTC (rev 41110)
+++ Zope3/trunk/src/zope/server/tests/test_serverbase.py	2006-01-03 19:02:50 UTC (rev 41111)
@@ -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