[telepathy-gabble/master] add block_reading optionnal arg to EventProtocol

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Thu May 7 07:08:03 PDT 2009


This can be used by tests which want to control when starting to read
from the transport.
---
 tests/twisted/servicetest.py        |   14 +++++++++++---
 tests/twisted/tubes/tubetestutil.py |    6 +++---
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/tests/twisted/servicetest.py b/tests/twisted/servicetest.py
index 45ecab4..7d919e5 100644
--- a/tests/twisted/servicetest.py
+++ b/tests/twisted/servicetest.py
@@ -345,9 +345,12 @@ def make_channel_proxy(conn, path, iface):
     chan = dbus.Interface(chan, tp_name_prefix + '.' + iface)
     return chan
 
+# block_reading can be used if the test want to choose when we start to read
+# data from the socket.
 class EventProtocol(Protocol):
-    def __init__(self, queue=None):
+    def __init__(self, queue=None, block_reading=False):
         self.queue = queue
+        self.block_reading = block_reading
 
     def dataReceived(self, data):
         if self.queue is not None:
@@ -357,12 +360,17 @@ class EventProtocol(Protocol):
     def sendData(self, data):
         self.transport.write(data)
 
+    def connectionMade(self):
+        if self.block_reading:
+            self.transport.stopReading()
+
 class EventProtocolFactory(Factory):
-    def __init__(self, queue):
+    def __init__(self, queue, block_reading=False):
         self.queue = queue
+        self.block_reading = block_reading
 
     def _create_protocol(self):
-        return EventProtocol(self.queue)
+        return EventProtocol(self.queue, self.block_reading)
 
     def buildProtocol(self, addr):
         proto = self._create_protocol()
diff --git a/tests/twisted/tubes/tubetestutil.py b/tests/twisted/tubes/tubetestutil.py
index fbbeba9..3fb6142 100644
--- a/tests/twisted/tubes/tubetestutil.py
+++ b/tests/twisted/tubes/tubetestutil.py
@@ -214,13 +214,13 @@ class Echo(EventProtocol):
 
 class EchoFactory(EventProtocolFactory):
     def _create_protocol(self):
-        return Echo(self.queue)
+        return Echo(self.queue, self.block_reading)
 
-def set_up_echo(q, address_type):
+def set_up_echo(q, address_type, block_reading=False):
     """
     Sets up an instance of Echo listening on a socket of type @address_type
     """
-    factory = EchoFactory(q)
+    factory = EchoFactory(q, block_reading)
     return create_server(q, address_type, factory)
 
 def connect_socket(q, address_type, address):
-- 
1.5.6.5




More information about the telepathy-commits mailing list