def hook_wrapper(prompt):
 try:
  res = ensure_str(readline_hook(prompt))
  if (res and (not isinstance(res, str))):
   raise TypeError, 'readline must return a string.'
 except KeyboardInterrupt:
  return 0
 except EOFError:
  res = ''
 except:
  print >>sys.stderr, 'Readline internal error'
  traceback.print_exc()
  res = '\n'
 p = cdll.msvcrt._strdup(res)
 return p

def hook_wrapper ( prompt ) : try : res = ensure_str ( readline_hook ( prompt ) ) if ( res and ( not isinstance ( res , str ) ) ) : raise TypeError , 'readline must return a string.' except KeyboardInterrupt : return 0 except EOFError : res = '' except : print >> sys . stderr , 'Readline internal error' traceback . print_exc ( ) res = '\n' p = cdll . msvcrt . _strdup ( res ) return p
wrap a python readline so it behaves like gnu readline .