[IPython-dev] Proposal for small change in dir2() function to handle XMLRPC Server Proxies

Marco Nawijn nawijn at gmail.com
Thu Oct 11 10:03:25 EDT 2012


Dear All,

I would to propose that a small change is made to the dir2() function
in IPython to better handle tab completion on a xmlrpclib.ServerProxy
object.

Currently if you do tab completion on a xmlrpclib.ServerProxy it a
traceback like the following is generated:

=== BEGIN TRACEBACK =====
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/IPython/core/completer.py",
line 847, in complete
    self.matches.extend(matcher(text))
  File "/usr/lib/python2.7/site-packages/IPython/core/completer.py",
line 641, in python_matches
    matches = self.attr_matches(text)
  File "/usr/lib/python2.7/site-packages/IPython/core/completer.py",
line 393, in attr_matches
    words = dir2(obj)
  File "/usr/lib/python2.7/site-packages/IPython/utils/dir2.py", line
64, in dir2
    words.extend(obj.trait_names())
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1578, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1297, in single_request
    return self.parse_response(response)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1473, in parse_response
    return u.close()
  File "/usr/lib64/python2.7/xmlrpclib.py", line 793, in close
    raise Fault(**self._stack[0])
Fault: <Fault 1: '<type \'exceptions.Exception\'>:method "trait_names"
is not supported'>

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev at scipy.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

===== END TRACEBACK ======

The source of this as can be seen from the traceback is in the dir2() function.
Since the main purpose of dir2 seems to be to handle border cases, I
would like to propose that an additional case is implemented to handle
 xmlrpclib.ServerProxy objects.

I have implemented it (as a proof of concept) as follows:

    import xmlrpclib
    if isinstance(obj, xmlrpclib.ServerProxy):
        words = obj.system.listMethods()
        return words
    else:
        words = dir(obj)      <- this is already there

It works like a charm :).

Any comments on this?

Kind regards,

Marco Nawijn



More information about the IPython-dev mailing list