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

Jim Fulton jim at zope.com
Sat Dec 24 11:45:03 EST 2005


Log message for revision 41023:
  Merged from 3.2 branch:
  
  ------------------------------------------------------------------------
    r40915 | jim | 2005-12-20 13:24:47 -0500 (Tue, 20 Dec 2005) | 2 lines
  
  Changed channels to accept non-string iterables.
  

Changed:
  U   Zope3/trunk/src/zope/server/dualmodechannel.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	2005-12-24 16:43:17 UTC (rev 41022)
+++ Zope3/trunk/src/zope/server/dualmodechannel.py	2005-12-24 16:45:02 UTC (rev 41023)
@@ -152,8 +152,14 @@
     #
 
     def write(self, data):
-        if data:
-            self.outbuf.append(data)
+        if isinstance(data, str):
+            if data:
+                self.outbuf.append(data)
+        else:
+            for v in data:
+                if v:
+                    self.outbuf.append(v)
+
         while len(self.outbuf) >= self.adj.send_bytes:
             # Send what we can without blocking.
             # We propagate errors to the application on purpose

Modified: Zope3/trunk/src/zope/server/tests/test_serverbase.py
===================================================================
--- Zope3/trunk/src/zope/server/tests/test_serverbase.py	2005-12-24 16:43:17 UTC (rev 41022)
+++ Zope3/trunk/src/zope/server/tests/test_serverbase.py	2005-12-24 16:45:02 UTC (rev 41023)
@@ -39,7 +39,54 @@
 
     """
 
+class FakeSocket:
+    data        = ''
+    setblocking = lambda *_: None
+    fileno      = lambda *_: 42
+    getpeername = lambda *_: ('localhost', 42)
 
+    def send(self, data):
+        self.data += data
+        return len(data)
+    
+
+def channels_accept_iterables():
+    r"""
+Channels accept iterables (they special-case strings).
+
+    >>> from zope.server.dualmodechannel import DualModeChannel
+    >>> socket = FakeSocket()
+    >>> channel = DualModeChannel(socket, ('localhost', 42))
+
+    >> channel.write("First")
+    >> channel.flush()
+    >> print socket.data
+    First
+
+    >>> channel.write(["First", "\n", "Second", "\n", "Third"])
+    >>> channel.flush()
+    >>> print socket.data
+    First
+    Second
+    Third
+
+    >>> def count():
+    ...     yield '\n1\n2\n3\n'
+    ...     yield 'I love to count. Ha ha ha.'
+
+    >>> channel.write(count())
+    >>> channel.flush()
+    >>> print socket.data
+    First
+    Second
+    Third
+    1
+    2
+    3
+    I love to count. Ha ha ha.
+    
+"""
+
 def test_suite():
     return doctest.DocTestSuite()
 



More information about the Zope3-Checkins mailing list