[Python-checkins] CVS: python/dist/src/Lib SimpleXMLRPCServer.py,1.1,1.2
Fred L. Drake
fdrake@users.sourceforge.net
Fri, 28 Sep 2001 21:54:35 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv22778
Modified Files:
SimpleXMLRPCServer.py
Log Message:
_dispatch(): Do no re-define the resolve_dotted_atttribute() function
every time this gets called; move it out as a global helper function.
Simplify the call to the _dispatch() method of the registered instance.
Index: SimpleXMLRPCServer.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/SimpleXMLRPCServer.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SimpleXMLRPCServer.py 2001/09/17 17:35:21 1.1
--- SimpleXMLRPCServer.py 2001/09/29 04:54:33 1.2
***************
*** 148,167 ****
"""
- 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:
--- 148,151 ----
***************
*** 172,183 ****
# check for a _dispatch method
if hasattr(self.server.instance, '_dispatch'):
! return apply(
! getattr(self.server.instance,'_dispatch'),
! (method, params)
! )
else:
# call instance method directly
try:
! func = resolve_dotted_attribute(
self.server.instance,
method
--- 156,164 ----
# check for a _dispatch method
if hasattr(self.server.instance, '_dispatch'):
! return self.server.instance._dispatch(method, params)
else:
# call instance method directly
try:
! func = _resolve_dotted_attribute(
self.server.instance,
method
***************
*** 196,199 ****
--- 177,195 ----
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):