Python termios 模块,OCRNL 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用termios.OCRNL

项目:FrozenBottle    作者:freieslabor    | 项目源码 | 文件源码
def __init__(self):
        global CIO_STARTED
        if CIO_STARTED:
            raise Exception("cannot init cio twice")
        CIO_STARTED = True
        self.buf=''
        self.fh_ocfg=list()
        if os.name == 'posix':
            # for posix, need to set to non-canonical input.
            self.posix=True
            fh = sys.stdin.fileno()
            # if the following call fails, we are probably called with a stdin which is not a tty.
            ocfg = termios.tcgetattr(fh)
            cfg = termios.tcgetattr(fh)
            cfg[3] = cfg[3]&~termios.ICANON&~termios.ECHO
            #cfg[0] = cfg[0]&~termios.INLCR
            #cfg[1] = cfg[0]&~termios.OCRNL
            cfg[6][termios.VMIN] = 0
            cfg[6][termios.VTIME] = 0
            termios.tcsetattr(fh,termios.TCSAFLUSH,cfg)
            self.fh_ocfg.extend((fh,ocfg))
            atexit.register(stop_canon_input,self.fh_ocfg)
        elif os.name == 'nt':
            # for windows, don't need to configure the terminal.
            self.posix=False
        else:
            # know only posix and windows...
            raise Exception("os variant %s not supported"%repr(os.name))