当前位置: 首页>>代码示例>>Python>>正文


Python termios.TCSANOW属性代码示例

本文整理汇总了Python中termios.TCSANOW属性的典型用法代码示例。如果您正苦于以下问题:Python termios.TCSANOW属性的具体用法?Python termios.TCSANOW怎么用?Python termios.TCSANOW使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在termios的用法示例。


在下文中一共展示了termios.TCSANOW属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def __init__(self, args, close_stderr=False):
    pid, fd = pty.fork()
    if pid == 0:
      # We're the child. Transfer control to command.
      if close_stderr:
        dev_null = os.open('/dev/null', 0)
        os.dup2(dev_null, 2)
      os.execvp(args[0], args)
    else:
      # Disable echoing.
      attr = termios.tcgetattr(fd)
      attr[3] = attr[3] & ~termios.ECHO
      termios.tcsetattr(fd, termios.TCSANOW, attr)
      # Set up a file()-like interface to the child process
      self.r = os.fdopen(fd, 'r', 1)
      self.w = os.fdopen(os.dup(fd), 'w', 1) 
开发者ID:google,项目名称:clusterfuzz,代码行数:18,代码来源:stack_symbolizer.py

示例2: init

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def init():
    if os.name == 'posix':
        global old
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0

        # -- Cambiar los atributos
        termios.tcsetattr(fd, termios.TCSANOW, new)

        # -- Restaurar el terminal a la salida
        atexit.register(cleanup_console)
    pass


# -------------------------------------
# Pequena prueba del modulo
# ------------------------------------- 
开发者ID:Obijuan,项目名称:simplez-fpga,代码行数:22,代码来源:consola_io.py

示例3: _set_baudrate

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def _set_baudrate(self, baudrate):
        if not isinstance(baudrate, int):
            raise TypeError("Invalid baud rate type, should be integer.")

        if baudrate not in Serial._BAUDRATE_TO_OSPEED:
            raise ValueError("Unknown baud rate: {:d}".format(baudrate))

        # Get tty attributes
        try:
            (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = termios.tcgetattr(self._fd)
        except termios.error as e:
            raise SerialError(e.errno, "Getting serial port attributes: " + e.strerror)

        # Modify tty attributes
        cflag &= ~(termios.CBAUD | termios.CBAUDEX)
        cflag |= Serial._BAUDRATE_TO_OSPEED[baudrate]
        ispeed = Serial._BAUDRATE_TO_OSPEED[baudrate]
        ospeed = Serial._BAUDRATE_TO_OSPEED[baudrate]

        # Set tty attributes
        try:
            termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:26,代码来源:serial.py

示例4: _set_databits

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def _set_databits(self, databits):
        if not isinstance(databits, int):
            raise TypeError("Invalid data bits type, should be integer.")
        elif databits not in [5, 6, 7, 8]:
            raise ValueError("Invalid data bits, can be 5, 6, 7, 8.")

        # Get tty attributes
        try:
            (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = termios.tcgetattr(self._fd)
        except termios.error as e:
            raise SerialError(e.errno, "Getting serial port attributes: " + e.strerror)

        # Modify tty attributes
        cflag &= ~termios.CSIZE
        cflag |= Serial._DATABITS_TO_CFLAG[databits]

        # Set tty attributes
        try:
            termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:23,代码来源:serial.py

示例5: _set_stopbits

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def _set_stopbits(self, stopbits):
        if not isinstance(stopbits, int):
            raise TypeError("Invalid stop bits type, should be integer.")
        elif stopbits not in [1, 2]:
            raise ValueError("Invalid stop bits, can be 1, 2.")

        # Get tty attributes
        try:
            (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = termios.tcgetattr(self._fd)
        except termios.error as e:
            raise SerialError(e.errno, "Getting serial port attributes: " + e.strerror)

        # Modify tty attributes
        cflag &= ~termios.CSTOPB
        if stopbits == 2:
            cflag |= termios.CSTOPB

        # Set tty attributes
        try:
            termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:24,代码来源:serial.py

示例6: _set_xonxoff

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def _set_xonxoff(self, enabled):
        if not isinstance(enabled, bool):
            raise TypeError("Invalid enabled type, should be boolean.")

        # Get tty attributes
        try:
            (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = termios.tcgetattr(self._fd)
        except termios.error as e:
            raise SerialError(e.errno, "Getting serial port attributes: " + e.strerror)

        # Modify tty attributes
        iflag &= ~(termios.IXON | termios.IXOFF | termios.IXANY)
        if enabled:
            iflag |= (termios.IXON | termios.IXOFF)

        # Set tty attributes
        try:
            termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:22,代码来源:serial.py

示例7: _set_vmin

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def _set_vmin(self, vmin):
        if not isinstance(vmin, int):
            raise TypeError("Invalid vmin type, should be integer.")
        elif not (0 <= vmin <= 255):
            raise ValueError("Invalid vmin, can be 0 to 255.")

        try:
            iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self._fd)
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror)

        cc[termios.VMIN] = vmin

        try:
            termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror)

        self._use_termios_timeout = vmin > 0 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:21,代码来源:serial.py

示例8: _set_vtime

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def _set_vtime(self, vtime):
        if not isinstance(vtime, (float, int)):
            raise TypeError("Invalid vtime type, should be float or integer.")
        elif not (0 <= vtime <= 25.5):
            raise ValueError("Invalid vtime, can be 0 to 25.5 seconds.")

        try:
            iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self._fd)
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror)

        cc[termios.VTIME] = int(float(vtime) * 10.0)

        try:
            termios.tcsetattr(self._fd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
        except termios.error as e:
            raise SerialError(e.errno, "Setting serial port attributes: " + e.strerror) 
开发者ID:vsergeev,项目名称:python-periphery,代码行数:19,代码来源:serial.py

示例9: launch_proc_with_pty

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def launch_proc_with_pty(args, stdin=None, stdout=None, stderr=None, echo=True):
    """Similar to pty.fork, but handle stdin/stdout according to parameters
    instead of connecting to the pty

    :return tuple (subprocess.Popen, pty_master)
    """

    def set_ctty(ctty_fd, master_fd):
        os.setsid()
        os.close(master_fd)
        fcntl.ioctl(ctty_fd, termios.TIOCSCTTY, 0)
        if not echo:
            termios_p = termios.tcgetattr(ctty_fd)
            # termios_p.c_lflags
            termios_p[3] &= ~termios.ECHO
            termios.tcsetattr(ctty_fd, termios.TCSANOW, termios_p)
    (pty_master, pty_slave) = os.openpty()
    # pylint: disable=not-an-iterable
    p = yield from asyncio.create_subprocess_exec(*args,
        stdin=stdin,
        stdout=stdout,
        stderr=stderr,
        preexec_fn=lambda: set_ctty(pty_slave, pty_master))
    os.close(pty_slave)
    return p, open(pty_master, 'wb+', buffering=0) 
开发者ID:QubesOS,项目名称:qubes-core-admin,代码行数:27,代码来源:backup.py

示例10: _setecho

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def _setecho(fd, state):
    errmsg = 'setecho() may not be called on this platform (it may still be possible to enable/disable echo when spawning the child process)'

    try:
        attr = termios.tcgetattr(fd)
    except termios.error as err:
        if err.args[0] == errno.EINVAL:
            raise IOError(err.args[0], '%s: %s.' % (err.args[1], errmsg))
        raise

    if state:
        attr[3] = attr[3] | termios.ECHO
    else:
        attr[3] = attr[3] & ~termios.ECHO

    try:
        # I tried TCSADRAIN and TCSAFLUSH, but these were inconsistent and
        # blocked on some platforms. TCSADRAIN would probably be ideal.
        termios.tcsetattr(fd, termios.TCSANOW, attr)
    except IOError as err:
        if err.args[0] == errno.EINVAL:
            raise IOError(err.args[0], '%s: %s.' % (err.args[1], errmsg))
        raise 
开发者ID:pypa,项目名称:pipenv,代码行数:25,代码来源:ptyprocess.py

示例11: _setecho

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def _setecho(fd, state):
    errmsg = 'setecho() may not be called on this platform'

    try:
        attr = termios.tcgetattr(fd)
    except termios.error as err:
        if err.args[0] == errno.EINVAL:
            raise IOError(err.args[0], '%s: %s.' % (err.args[1], errmsg))
        raise

    if state:
        attr[3] = attr[3] | termios.ECHO
    else:
        attr[3] = attr[3] & ~termios.ECHO

    try:
        # I tried TCSADRAIN and TCSAFLUSH, but these were inconsistent and
        # blocked on some platforms. TCSADRAIN would probably be ideal.
        termios.tcsetattr(fd, termios.TCSANOW, attr)
    except IOError as err:
        if err.args[0] == errno.EINVAL:
            raise IOError(err.args[0], '%s: %s.' % (err.args[1], errmsg))
        raise 
开发者ID:daveleroy,项目名称:sublime_debugger,代码行数:25,代码来源:ptyprocess.py

示例12: main

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def main():
    """This main function saves the stdin termios settings, calls real_main,
       and restores stdin termios settings when it returns.
    """
    save_settings = None
    stdin_fd = -1
    try:
        import termios
        stdin_fd = sys.stdin.fileno()
        save_settings = termios.tcgetattr(stdin_fd)
    except:
        pass
    try:
        real_main()
    finally:
        if save_settings:
            termios.tcsetattr(stdin_fd, termios.TCSANOW, save_settings) 
开发者ID:dhylands,项目名称:rshell,代码行数:19,代码来源:main.py

示例13: wait_key

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def wait_key():
    """ Wait for a key press on the console and return it. """
    result = None
    if os.name == 'nt':
        result = input("Press Enter to continue...")
    else:
        import termios
        fd = sys.stdin.fileno()

        oldterm = termios.tcgetattr(fd)
        newattr = termios.tcgetattr(fd)
        newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
        termios.tcsetattr(fd, termios.TCSANOW, newattr)

        try:
            result = sys.stdin.read(1)
        except IOError:
            pass
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)

    return result 
开发者ID:donwayo,项目名称:ebayKleinanzeigen,代码行数:24,代码来源:kleinanzeigen.py

示例14: getch

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def getch():
        """getch function
        """
        fd = sys.stdin.fileno()
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0
        termios.tcsetattr(fd, termios.TCSANOW, new)
        key = None
        try:
            key = os.read(fd, 80)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
        return key 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:18,代码来源:console.py

示例15: getch

# 需要导入模块: import termios [as 别名]
# 或者: from termios import TCSANOW [as 别名]
def getch():
        """Make a get character keyboard method for Posix machines.
        """
        fd = sys.stdin.fileno()
        old = termios.tcgetattr(fd)
        new = termios.tcgetattr(fd)
        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
        new[6][termios.VMIN] = 1
        new[6][termios.VTIME] = 0
        termios.tcsetattr(fd, termios.TCSANOW, new)
        key = None
        try:
            key = os.read(fd, 4)
        finally:
            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
        return key 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:18,代码来源:failover_console.py


注:本文中的termios.TCSANOW属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。