Skip to content

Commit c1508c9

Browse files
committed
Added __call__ and __close methods to ServerProxy
- Allows to use the 'client("close")()' method to close the transport layer of a ServerProxy, even on Python 2.6 => Fixes joshmarshall#2 - Updated tests to _really_ close the transport layer (and not just to retrieve the closing method)
1 parent ad0ed6e commit c1508c9

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

jsonrpclib/jsonrpc.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,29 @@ def __getattr__(self, name):
386386
# Same as original, just with new _Method reference
387387
return _Method(self._request, name)
388388

389+
def __close(self):
390+
"""
391+
Closes the transport layer
392+
"""
393+
self.__transport.close()
394+
395+
396+
def __call__(self, attr):
397+
"""
398+
A workaround to get special attributes on the ServerProxy
399+
without interfering with the magic __getattr__
400+
401+
(code from xmlrpclib in Python 2.7)
402+
"""
403+
if attr == "close":
404+
return self.__close
405+
406+
elif attr == "transport":
407+
return self.__transport
408+
409+
raise AttributeError("Attribute {0} not found".format(attr))
410+
411+
389412
@property
390413
def _notify(self):
391414
# Just like __getattr__, but with notify namespace.

tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def tearDown(self):
190190
Post-test clean up
191191
"""
192192
# Close the client
193-
self.client("close")
193+
self.client("close")()
194194

195195
# Stop the server
196196
self.server.stop()

0 commit comments

Comments
 (0)