This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Expose callback API in readline module
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Expose non-blocking callbackAPI in readline module
View: 1744456
Assigned To: Nosy List: BreamoreBoy, christian.heimes, georg.brandl, strank
Priority: normal Keywords:

Created on 2007-05-06 18:07 by strank, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg55104 - (view) Author: strank (strank) Date: 2007-05-06 18:07
This is a request to expose the `callback API`_ of GNU readline in the readline module in the Python library.

.. _callback API: http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC41

This interface is suitable for asynchronous use, such as with twisted.

It is possible to expose the functions on Unix with ctypes::

  import readline
  import ctypes

  rl_lib = ctypes.cdll.LoadLibrary("libreadline.so.5")

  readline.callback_handler_remove = rl_lib.rl_callback_handler_remove
  readline.callback_read_char = rl_lib.rl_callback_read_char
  # the callback needs special treatment:
  rlcallbackfunctype = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p)
  def setcallbackfunc(prompt, thefunc):
      rl_lib.rl_callback_handler_install(prompt, rlcallbackfunctype(thefunc))
  readline.callback_handler_install = setcallbackfunc

but it would be much better to expose them "officially".
msg59362 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-06 12:43
A patch is always welcome
msg59435 - (view) Author: strank (strank) Date: 2008-01-07 07:13
I am pretty sure I posted a patch in the sf patch tracker... oh yes,
here it is: http://bugs.python.org/issue1744456

I think it still needs some work if you want to make it impossible for
users of the API to wreck the interactive prompt. If this possibility is
considered ok (it does not make sense to use the callback api from the
interactive prompt anyway), I think it's ok.

But someone with more readline experience should probably look at it... :-)
msg109839 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-10 10:11
Can this be closed as a duplicate as Issue1744456 has a patch?
msg109842 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-10 10:26
Yes, that makes sense (the two issues come from the SourceForge era, where bugs and patches had different trackers).
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 44935
2010-07-10 10:26:25georg.brandlsetstatus: open -> closed

dependencies: - Expose non-blocking callbackAPI in readline module
superseder: Expose non-blocking callbackAPI in readline module

nosy: + georg.brandl
messages: + msg109842
resolution: duplicate
2010-07-10 10:11:16BreamoreBoysetnosy: + BreamoreBoy
messages: + msg109839
2009-04-06 10:30:11ajaksu2setdependencies: + Expose non-blocking callbackAPI in readline module
versions: + Python 3.1, Python 2.7, - Python 2.6
2008-01-07 07:13:04stranksetmessages: + msg59435
2008-01-06 12:43:11christian.heimessetnosy: + christian.heimes
messages: + msg59362
2008-01-06 12:43:02christian.heimessetversions: + Python 2.6
2007-05-06 18:07:07strankcreate