Skip to content

Commit d0bb17b

Browse files
author
fdrake
committed
_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. git-svn-id: http://svn.python.org/projects/python/trunk@23438 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 5e01712 commit d0bb17b

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

Lib/SimpleXMLRPCServer.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,6 @@ def _dispatch(self, method, params):
147147
not be called by SimpleXMLRPCServer.
148148
"""
149149

150-
def resolve_dotted_attribute(obj, attr):
151-
"""resolve_dotted_attribute(math, 'cos.__doc__') => math.cos.__doc__
152-
153-
Resolves a dotted attribute name to an object. Raises
154-
an AttributeError if any attribute in the chain starts
155-
with a '_'.
156-
"""
157-
for i in attr.split('.'):
158-
if i.startswith('_'):
159-
raise AttributeError(
160-
'attempt to access private attribute "%s"' % i
161-
)
162-
else:
163-
obj = getattr(obj,i)
164-
return obj
165-
166150
func = None
167151
try:
168152
# check to see if a matching function has been registered
@@ -171,14 +155,11 @@ def resolve_dotted_attribute(obj, attr):
171155
if self.server.instance is not None:
172156
# check for a _dispatch method
173157
if hasattr(self.server.instance, '_dispatch'):
174-
return apply(
175-
getattr(self.server.instance,'_dispatch'),
176-
(method, params)
177-
)
158+
return self.server.instance._dispatch(method, params)
178159
else:
179160
# call instance method directly
180161
try:
181-
func = resolve_dotted_attribute(
162+
func = _resolve_dotted_attribute(
182163
self.server.instance,
183164
method
184165
)
@@ -196,6 +177,21 @@ def log_request(self, code='-', size='-'):
196177
if self.server.logRequests:
197178
BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size)
198179

180+
181+
def _resolve_dotted_attribute(obj, attr):
182+
"""Resolves a dotted attribute name to an object. Raises
183+
an AttributeError if any attribute in the chain starts with a '_'.
184+
"""
185+
for i in attr.split('.'):
186+
if i.startswith('_'):
187+
raise AttributeError(
188+
'attempt to access private attribute "%s"' % i
189+
)
190+
else:
191+
obj = getattr(obj,i)
192+
return obj
193+
194+
199195
class SimpleXMLRPCServer(SocketServer.TCPServer):
200196
"""Simple XML-RPC server.
201197

0 commit comments

Comments
 (0)