]> granicus.if.org Git - python/commitdiff
_dispatch(): Do no re-define the resolve_dotted_atttribute() function
authorFred Drake <fdrake@acm.org>
Sat, 29 Sep 2001 04:54:33 +0000 (04:54 +0000)
committerFred Drake <fdrake@acm.org>
Sat, 29 Sep 2001 04:54:33 +0000 (04:54 +0000)
    every time this gets called; move it out as a global helper function.
    Simplify the call to the _dispatch() method of the registered instance.

Lib/SimpleXMLRPCServer.py

index 89900bd75ecb2c4324814f511fc67436cb71b69e..0a9168387acf65084ea1b953ce00fdfbe6b3e179 100644 (file)
@@ -147,22 +147,6 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
         not be called by SimpleXMLRPCServer.
         """
 
-        def resolve_dotted_attribute(obj, attr):
-            """resolve_dotted_attribute(math, 'cos.__doc__') => math.cos.__doc__
-
-            Resolves a dotted attribute name to an object. Raises
-            an AttributeError if any attribute in the chain starts
-            with a '_'.
-            """
-            for i in attr.split('.'):
-                if i.startswith('_'):
-                    raise AttributeError(
-                        'attempt to access private attribute "%s"' % i
-                        )
-                else:
-                    obj = getattr(obj,i)
-            return obj
-
         func = None
         try:
             # check to see if a matching function has been registered
@@ -171,14 +155,11 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
             if self.server.instance is not None:
                 # check for a _dispatch method
                 if hasattr(self.server.instance, '_dispatch'):
-                    return apply(
-                        getattr(self.server.instance,'_dispatch'),
-                        (method, params)
-                        )
+                    return self.server.instance._dispatch(method, params)
                 else:
                     # call instance method directly
                     try:
-                        func = resolve_dotted_attribute(
+                        func = _resolve_dotted_attribute(
                             self.server.instance,
                             method
                             )
@@ -196,6 +177,21 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
         if self.server.logRequests:
             BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size)
 
+
+def _resolve_dotted_attribute(obj, attr):
+    """Resolves a dotted attribute name to an object.  Raises
+    an AttributeError if any attribute in the chain starts with a '_'.
+    """
+    for i in attr.split('.'):
+        if i.startswith('_'):
+            raise AttributeError(
+                'attempt to access private attribute "%s"' % i
+                )
+        else:
+            obj = getattr(obj,i)
+    return obj
+
+
 class SimpleXMLRPCServer(SocketServer.TCPServer):
     """Simple XML-RPC server.