# # This is a stub module that imports the real 'readline.so' under the # hood, unless sys.stdout is not a tty, in which case stub functions # are installed and 'readline.so' is not imported at all. This is # a workaround for issues caused by 'import readline' writing a few # control characters to stdout even if it is not a tty -- at least # this occurs in some configurations. # import os, sys __all__ = ['add_history', 'clear_history', 'get_begidx', 'get_completer', 'get_completer_delims', 'get_current_history_length', 'get_endidx', 'get_history_item', 'get_history_length', 'get_line_buffer', 'insert_text', 'parse_and_bind', 'read_history_file', 'read_init_file', 'redisplay', 'remove_history_item', 'replace_history_item', 'set_completer', 'set_completer_delims', 'set_history_length', 'set_pre_input_hook', 'set_startup_hook', 'write_history_file'] if os.isatty(1): #sofile = (sys.exec_prefix + # '/lib/python%d.%d/lib-dynload/readline.so' % sys.version_info[:2]) for _path in sys.path: sofile = os.path.join(_path, 'readline.so') if os.path.exists(sofile): import imp _mod = imp.load_module('readline', None, sofile, ('.so', 'rb', imp.C_EXTENSION)) break else: # cannot locate the original readline.so! # Maybe running on top of pypy. Let's use pypy/lib/pyrepl/readline. from pypy.lib.pyrepl import readline as _mod globals().update(_mod.__dict__) else: def _readline_stub(*args, **kwds): pass for _name in __all__: globals()[_name] = _readline_stub