[Zodb-checkins] CVS: ZODB3/ZEO/zrpc - connection.py:1.42

Jeremy Hylton jeremy@zope.com
Tue, 7 Jan 2003 14:25:25 -0500


Update of /cvs-repository/ZODB3/ZEO/zrpc
In directory cvs.zope.org:/tmp/cvs-serv21568/ZEO/zrpc

Modified Files:
	connection.py 
Log Message:
Add _deferred_call() and _deferred_wait() for testing purposes.

XXX The deferred name isn't perfect, but async is already taken.


=== ZODB3/ZEO/zrpc/connection.py 1.41 => 1.42 ===
--- ZODB3/ZEO/zrpc/connection.py:1.41	Fri Jan  3 17:07:41 2003
+++ ZODB3/ZEO/zrpc/connection.py	Tue Jan  7 14:25:21 2003
@@ -349,6 +349,29 @@
         else:
             return r_args
 
+    # For testing purposes, it is useful to begin a synchronous call
+    # but not block waiting for its response.  Since these methods are
+    # used for testing they can assume they are not in async mode and
+    # call asyncore.poll() directly to get the message out without
+    # also waiting for the reply.
+
+    def _deferred_call(self, method, *args):
+        if self.closed:
+            raise DisconnectedError()
+        msgid = self.send_call(method, args, 0)
+        asyncore.poll(0.01, self._map)
+        return msgid
+
+    def _deferred_wait(self, msgid):
+        r_flags, r_args = self.wait(msgid)
+        if (isinstance(r_args, types.TupleType)
+            and type(r_args[0]) == types.ClassType
+            and issubclass(r_args[0], Exception)):
+            inst = r_args[1]
+            raise inst # error raised by server
+        else:
+            return r_args
+
     def callAsync(self, method, *args):
         if self.closed:
             raise DisconnectedError()