[Zodb-checkins] SVN: ZODB/branches/jim-3.8-connection/src/ZEO/zrpc/c Allow the connection object to be None, in which case messages to the

Jim Fulton jim at zope.com
Fri Jul 11 17:41:36 EDT 2008


Log message for revision 88270:
  Allow the connection object to be None, in which case messages to the
  object are discarded. This is to avoid sending invalidations to a
  client when it isn't ready or from requests that aren't used.
  
  Don't initially set the connection object for managed client
  connections.  The object will be set by the client when it connects.
  

Changed:
  U   ZODB/branches/jim-3.8-connection/src/ZEO/zrpc/client.py
  U   ZODB/branches/jim-3.8-connection/src/ZEO/zrpc/connection.py

-=-
Modified: ZODB/branches/jim-3.8-connection/src/ZEO/zrpc/client.py
===================================================================
--- ZODB/branches/jim-3.8-connection/src/ZEO/zrpc/client.py	2008-07-11 21:41:31 UTC (rev 88269)
+++ ZODB/branches/jim-3.8-connection/src/ZEO/zrpc/client.py	2008-07-11 21:41:34 UTC (rev 88270)
@@ -447,8 +447,7 @@
         Call the client's testConnection(), giving the client a chance
         to do app-level check of the connection.
         """
-        self.conn = ManagedClientConnection(self.sock, self.addr,
-                                            self.client, self.mgr)
+        self.conn = ManagedClientConnection(self.sock, self.addr, self.mgr)
         self.sock = None # The socket is now owned by the connection
         try:
             self.preferred = self.client.testConnection(self.conn)

Modified: ZODB/branches/jim-3.8-connection/src/ZEO/zrpc/connection.py
===================================================================
--- ZODB/branches/jim-3.8-connection/src/ZEO/zrpc/connection.py	2008-07-11 21:41:31 UTC (rev 88269)
+++ ZODB/branches/jim-3.8-connection/src/ZEO/zrpc/connection.py	2008-07-11 21:41:34 UTC (rev 88270)
@@ -555,14 +555,23 @@
             self.replies_cond.release()
 
     def handle_request(self, msgid, flags, name, args):
-        if not self.check_method(name):
-            msg = "Invalid method name: %s on %s" % (name, repr(self.obj))
+        obj = self.obj
+        
+        if name.startswith('_') or not hasattr(obj, name):
+            if obj is None:
+                if __debug__:
+                    self.log("no object calling %s%s"
+                             % (name, short_repr(args)),
+                             level=logging.DEBUG)
+                return
+                
+            msg = "Invalid method name: %s on %s" % (name, repr(obj))
             raise ZRPCError(msg)
         if __debug__:
             self.log("calling %s%s" % (name, short_repr(args)),
                      level=logging.DEBUG)
 
-        meth = getattr(self.obj, name)
+        meth = getattr(obj, name)
         try:
             self.waiting_for_reply = True
             try:
@@ -601,12 +610,6 @@
                  level=logging.ERROR, exc_info=True)
         self.close()
 
-    def check_method(self, name):
-        # TODO:  This is hardly "secure".
-        if name.startswith('_'):
-            return None
-        return hasattr(self.obj, name)
-
     def send_reply(self, msgid, ret):
         # encode() can pass on a wide variety of exceptions from cPickle.
         # While a bare `except` is generally poor practice, in this case
@@ -897,7 +900,7 @@
     __super_close = Connection.close
     base_message_output = Connection.message_output
 
-    def __init__(self, sock, addr, obj, mgr):
+    def __init__(self, sock, addr, mgr):
         self.mgr = mgr
 
         # We can't use the base smac's message_output directly because the
@@ -914,7 +917,7 @@
         self.queue_output = True
         self.queued_messages = []
 
-        self.__super_init(sock, addr, obj, tag='C', map=client_map)
+        self.__super_init(sock, addr, None, tag='C', map=client_map)
         self.thr_async = True
         self.trigger = client_trigger
         client_trigger.pull_trigger()



More information about the Zodb-checkins mailing list