readline.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:pyrepl 作者: dajose 项目源码 文件源码
def _setup():
    global _old_raw_input
    if _old_raw_input is not None:
        return
    # don't run _setup twice

    try:
        f_in = sys.stdin.fileno()
        f_out = sys.stdout.fileno()
    except (AttributeError, ValueError):
        return
    if not os.isatty(f_in) or not os.isatty(f_out):
        return

    _wrapper.f_in = f_in
    _wrapper.f_out = f_out

    if '__pypy__' in sys.builtin_module_names:    # PyPy

        def _old_raw_input(prompt=''):
            # sys.__raw_input__() is only called when stdin and stdout are
            # as expected and are ttys.  If it is the case, then get_reader()
            # should not really fail in _wrapper.raw_input().  If it still
            # does, then we will just cancel the redirection and call again
            # the built-in raw_input().
            try:
                del sys.__raw_input__
            except AttributeError:
                pass
            return raw_input(prompt)
        sys.__raw_input__ = _wrapper.raw_input

    else:
        # this is not really what readline.c does.  Better than nothing I guess
        import __builtin__
        try:
            import __builtin__
            _old_raw_input = __builtin__.raw_input
            __builtin__.raw_input = _wrapper.raw_input
        except ImportError:
            import builtins
            _old_raw_input = builtins.input
            builtins.input = _wrapper.raw_input
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号