Pascal Peregrina wrote at 2005-6-27 11:53 +0200:
>I just finished reading xmlrpclib.py and ZopeProfiler code.
>
>Here is the root cause of the issue :
>
>In my code :
> getattr(ServerProxy(self.url),self.rpc_method_expr) returns an
>xmlrpclib._Method object
>
>Then ZopeProfiler calls
>ZopeProfiler.ZopeProfiler.getHLFuncId(self,fn,frame), which contains:
>gP= getattr(s,'getPhysicalPath',None)
>
>So this calls xmlrpclib._Method.__getattr__, which is:
>    def __getattr__(self, name):
>        return _Method(self.__send, "%s.%s" % (self.__name, name))
>
>So this returns another xmlrpclib._Method object for a "getPhysicalPath" RPC
>method
>
>Because gP is not None, ZopeProfiler then does :
>p= gP()
>
>And this makes an RPC method call on the service, and of course raises an
>Exception !

Nice analysis!

>So for my tests I hacked xmlrpclib._Method.__getattr__ to return None for
>'getPhysicalPath' :
>    def __getattr__(self, name):
>        if name=='getPhysicalPath':
>            return None
>        return _Method(self.__send, "%s.%s" % (self.__name, name))

You can do this easier:

    from xmlrpclib import _Method
    _Method.getPhysicalPath = None

Of course, any way, you will loose the possibility to
call "getPhysicalPath" via "XML-RPC".

>
>But a real fix will be needed on ZopeProfiler !

Try the attached patch.


-- 
Dieter

--- ZopeProfiler.py~	2005-03-26 11:09:23.000000000 +0100
+++ ZopeProfiler.py	2005-06-27 19:53:31.000000000 +0200
@@ -379,6 +379,17 @@
     s= l.get('self')
     gP= getattr(s,'getPhysicalPath',None)
     if gP is None: return
+    # Try to work around a problem with funny classes returning
+    #   instances of itself for "getPhysicalPath".
+    #   "xmlrpclib._Method" is such a funny class
+    #   Problem reported by "[EMAIL PROTECTED]"
+    #
+    #   Note that a clean fix would require interfaces with
+    #   a specific interface indicating that "getPhysicalPath" is
+    #   the method we expect.
+    s_class = getattr(s, '__class__', None)
+    gpp_class = getattr(s, '__class__', None)
+    if s_class is not None and s_class is gpp_class: return
     p= gP()
     if type(p) is StringType: fi= p
     else: fi= '/'.join(p)
_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to