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


Python pty.openpty方法代码示例

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


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

示例1: start_x

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def start_x(a, b):
    from pdb import Pdb
    import os
    from pty import openpty

    (master, slave) = openpty()
    cmd = "rxvt -pty-fd {} &".format(master)
    os.system(cmd)
    io = os.fdopen(slave, "r+b")
    Pdb(stdin=io, stdout=io).set_trace()


# set a handler on SIGUSR1. NB although all the above shoudln't really
# work as signal handlers, because they call system calls which you are
# not supposed to use in a handler, these are okay because in fact
# python is handling the signal in C then interpreting these 'handlers'
# outside the handler.

# To use: pydebug.patch_handler(pydebug.start_x) 
开发者ID:KanoComputing,项目名称:kano-toolset,代码行数:21,代码来源:pydebug.py

示例2: test_ioctl_signed_unsigned_code_param

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def test_ioctl_signed_unsigned_code_param(self):
        if not pty:
            raise unittest.SkipTest('pty module required')
        mfd, sfd = pty.openpty()
        try:
            if termios.TIOCSWINSZ < 0:
                set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ
                set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffffL
            else:
                set_winsz_opcode_pos = termios.TIOCSWINSZ
                set_winsz_opcode_maybe_neg, = struct.unpack("i",
                        struct.pack("I", termios.TIOCSWINSZ))

            our_winsz = struct.pack("HHHH",80,25,0,0)
            # test both with a positive and potentially negative ioctl code
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz)
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
        finally:
            os.close(mfd)
            os.close(sfd) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_ioctl.py

示例3: test_ioctl_signed_unsigned_code_param

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def test_ioctl_signed_unsigned_code_param(self):
        if not pty:
            raise unittest.SkipTest('pty module required')
        mfd, sfd = pty.openpty()
        try:
            if termios.TIOCSWINSZ < 0:
                set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ
                set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffff
            else:
                set_winsz_opcode_pos = termios.TIOCSWINSZ
                set_winsz_opcode_maybe_neg, = struct.unpack("i",
                        struct.pack("I", termios.TIOCSWINSZ))

            our_winsz = struct.pack("HHHH",80,25,0,0)
            # test both with a positive and potentially negative ioctl code
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz)
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
        finally:
            os.close(mfd)
            os.close(sfd) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_ioctl.py

示例4: __init__

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def __init__(self, height=25, width=80):

        self.master, self.slave = pty.openpty()

        if sys.version_info[:2] < (2, 7):
            self.stdout = os.fdopen(self.slave, 'w', 1)
            self.stdread = os.fdopen(self.master, 'r')
        else:
            self.stdout = io.open(self.slave, 'w', 1, encoding='UTF-8', newline='')
            self.stdread = io.open(self.master, 'r', encoding='UTF-8', newline='\n')

        # Make sure linefeed behavior is consistent between Python 2 and Python 3
        termattrs = termios.tcgetattr(self.slave)
        termattrs[1] = termattrs[1] & ~termios.ONLCR & ~termios.OCRNL
        termattrs[0] = termattrs[0] & ~termios.ICRNL
        termios.tcsetattr(self.slave, termios.TCSADRAIN, termattrs)

        self.resize(height, width) 
开发者ID:Rockhopper-Technologies,项目名称:enlighten,代码行数:20,代码来源:__init__.py

示例5: test_ioctl_signed_unsigned_code_param

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def test_ioctl_signed_unsigned_code_param(self):
        if not pty:
            raise TestSkipped('pty module required')
        mfd, sfd = pty.openpty()
        try:
            if termios.TIOCSWINSZ < 0:
                set_winsz_opcode_maybe_neg = termios.TIOCSWINSZ
                set_winsz_opcode_pos = termios.TIOCSWINSZ & 0xffffffffL
            else:
                set_winsz_opcode_pos = termios.TIOCSWINSZ
                set_winsz_opcode_maybe_neg, = struct.unpack("i",
                        struct.pack("I", termios.TIOCSWINSZ))

            # We're just testing that these calls do not raise exceptions.
            saved_winsz = fcntl.ioctl(mfd, termios.TIOCGWINSZ, "\0"*8)
            our_winsz = struct.pack("HHHH",80,25,0,0)
            # test both with a positive and potentially negative ioctl code
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_pos, our_winsz)
            new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
            fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, saved_winsz)
        finally:
            os.close(mfd)
            os.close(sfd) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:25,代码来源:test_ioctl.py

示例6: handle

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def handle(self):
        masterFd, slaveFd = pty.openpty()
        try:
            # if we're not in the main thread, this will not work.
            signal.signal(signal.SIGTTOU, signal.SIG_IGN)
        except:  # noqa
            pass
        pid = os.fork()
        if pid:
            os.close(masterFd)
            raise SocketConnected(slaveFd, pid)
            # make parent process the pty slave - the opposite of
            # pty.fork().  In this setup, the parent process continues
            # to act normally, while the child process performs the
            # logging.  This makes it simple to kill the logging process
            # when we are done with it and restore the parent process to
            # normal, unlogged operation.
        else:
            os.close(slaveFd)
            try:
                protocol = TelnetServerProtocolHandler(self.request, masterFd)
                protocol.handle()
            finally:
                os.close(masterFd)
                os._exit(1) 
开发者ID:sassoftware,项目名称:epdb,代码行数:27,代码来源:epdb_server.py

示例7: open_terminal

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def open_terminal(dimensions):
    """
    Open pseudo-Terminal and configure it's dimensions

    :param dimensions: terminal dimensions (rows, columns)
    :return: (master, slave) file descriptors of Pty
    """
    master, slave = pty.openpty()
    _setwinsize(master, dimensions[0], dimensions[1])  # without this you get newline after each character
    _setwinsize(slave, dimensions[0], dimensions[1])
    return master, slave 
开发者ID:nokia,项目名称:moler,代码行数:13,代码来源:terminal.py

示例8: __init__

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def __init__(self, height):
        super(Terminal, self).__init__(height, line_wrap=True, parser=AnsiTerminalParser())

        #Key definitions
        self._map = {}
        for k, v in [
            (Screen.KEY_LEFT, "kcub1"),
            (Screen.KEY_RIGHT, "kcuf1"),
            (Screen.KEY_UP, "kcuu1"),
            (Screen.KEY_DOWN, "kcud1"),
            (Screen.KEY_HOME, "khome"),
            (Screen.KEY_END, "kend"),
            (Screen.KEY_BACK, "kbs"),
        ]:
            self._map[k] = curses.tigetstr(v)
        self._map[Screen.KEY_TAB] = "\t".encode()

        # Open a pseudo TTY to control the interactive session.  Make it non-blocking.
        self._master, slave = pty.openpty()
        fl = fcntl.fcntl(self._master, fcntl.F_GETFL)
        fcntl.fcntl(self._master, fcntl.F_SETFL, fl | os.O_NONBLOCK)

        # Start the shell and thread to pull data from it.
        self._shell = subprocess.Popen(["bash", "-i"], preexec_fn=os.setsid, stdin=slave, stdout=slave, stderr=slave)
        self._lock = threading.Lock()
        self._thread = threading.Thread(target=self._background)
        self._thread.daemon = True
        self._thread.start() 
开发者ID:peterbrittain,项目名称:asciimatics,代码行数:30,代码来源:terminal.py

示例9: __init__

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def __init__(self):
        self._master, self._slave = pty.openpty()
        self._s_name = os.ttyname(self._slave)

        self._fake = Faker()

        self._fake_device = threading.Thread(target=self.__run) 
开发者ID:Ousret,项目名称:pyTeliumManager,代码行数:9,代码来源:test_tpe.py

示例10: getPty

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def getPty(self, term, windowSize, modes):
        self.environ['TERM'] = term
        self.winSize = windowSize
        self.modes = modes
        master, slave = pty.openpty()
        ttyname = os.ttyname(slave)
        self.environ['SSH_TTY'] = ttyname
        self.ptyTuple = (master, slave, ttyname) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:unix.py

示例11: execute_interactive

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def execute_interactive(cmd: List[str], **kwargs):
    """
    Runs the new command as a subprocess and ensures that the terminal's state is restored to its original
    state after the process is completed e.g. if the subprocess hides the cursor, it will be restored after
    the process is completed.
    """
    log.info("Executing cmd: %s", " ".join([shlex.quote(c) for c in cmd]))

    old_tty = termios.tcgetattr(sys.stdin)
    tty.setraw(sys.stdin.fileno())

    # open pseudo-terminal to interact with subprocess
    master_fd, slave_fd = pty.openpty()
    try:  # pylint: disable=too-many-nested-blocks
        # use os.setsid() make it run in a new process group, or bash job control will not be enabled
        proc = subprocess.Popen(
            cmd,
            stdin=slave_fd,
            stdout=slave_fd,
            stderr=slave_fd,
            universal_newlines=True,
            **kwargs
        )

        while proc.poll() is None:
            readable_fbs, _, _ = select.select([sys.stdin, master_fd], [], [])
            if sys.stdin in readable_fbs:
                input_data = os.read(sys.stdin.fileno(), 10240)
                os.write(master_fd, input_data)
            if master_fd in readable_fbs:
                output_data = os.read(master_fd, 10240)
                if output_data:
                    os.write(sys.stdout.fileno(), output_data)
    finally:
        # restore tty settings back
        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty) 
开发者ID:apache,项目名称:airflow,代码行数:38,代码来源:process_utils.py

示例12: run

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def run(self):
        try:
            # use a pty. This enforces unbuffered output and thus
            # allows for fast update
            master_out_fd, slave_out_fd = pty.openpty()
            master_in_fd, self.slave_in_fd = pty.openpty()
            self.proc = subprocess.Popen(self.cmd, stdin=master_in_fd, stdout=slave_out_fd, stderr=slave_out_fd)
        except:
            self.finished.emit(False)
            return

        # listen to process' output
        while self.proc.poll() == None:
            try:
                if select.select([master_out_fd], [], [master_out_fd], .1)[0]:
                    output = os.read(master_out_fd, 100)
                    if output: self.output(str(output, "utf-8"))
            except InterruptedError:
                pass

        os.close(master_out_fd)
        os.close(slave_out_fd)

        os.close(master_in_fd)
        os.close(self.slave_in_fd)

        self.finished.emit(self.proc.wait() == 0) 
开发者ID:ftCommunity,项目名称:ftcommunity-TXT,代码行数:29,代码来源:netreq.py

示例13: __init__

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def __init__(  # pylint: disable=too-many-arguments
            self,
            args: List[str],
            print_output: bool = True,
            capture_input: bool = True,
            default_questions: Dict[str, List[str]] = None,
            **kwargs
    ) -> None:
        self.args = args
        self.print_output = print_output
        self.capture_input = capture_input
        self.default_questions = {}
        self.historic_output = []
        if default_questions:
            self.add_answers(default_questions)

        self.pty_user_master, self.pty_user_slave = pty.openpty()
        self.pty_cmd_master, self.pty_cmd_slave = pty.openpty()

        super().__init__(  # type: ignore[call-arg]
            args=args,
            stdin=self.pty_user_slave,
            stdout=self.pty_cmd_slave,
            stderr=self.pty_cmd_slave,
            **kwargs
        ) 
开发者ID:actionless,项目名称:pikaur,代码行数:28,代码来源:pikspect.py

示例14: _run_command

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def _run_command(cmd, clear_streamed_output):
  """Calls the shell command, forwarding input received on the stdin_socket."""
  locale_encoding = locale.getpreferredencoding()
  if locale_encoding != _ENCODING:
    raise NotImplementedError(
        'A UTF-8 locale is required. Got {}'.format(locale_encoding))

  parent_pty, child_pty = pty.openpty()
  _configure_term_settings(child_pty)

  epoll = select.epoll()
  epoll.register(
      parent_pty,
      (select.EPOLLIN | select.EPOLLOUT | select.EPOLLHUP | select.EPOLLERR))

  try:
    temporary_clearer = _tags.temporary if clear_streamed_output else _no_op

    with temporary_clearer(), _display_stdin_widget(
        delay_millis=500) as update_stdin_widget:
      # TODO(b/115531839): Ensure that subprocesses are terminated upon
      # interrupt.
      p = subprocess.Popen(
          cmd,
          shell=True,
          executable='/bin/bash',
          stdout=child_pty,
          stdin=child_pty,
          stderr=child_pty,
          close_fds=True)
      # The child PTY is only needed by the spawned process.
      os.close(child_pty)

      return _monitor_process(parent_pty, epoll, p, cmd, update_stdin_widget)
  finally:
    epoll.close()
    os.close(parent_pty) 
开发者ID:googlecolab,项目名称:colabtools,代码行数:39,代码来源:_system_commands.py

示例15: port

# 需要导入模块: import pty [as 别名]
# 或者: from pty import openpty [as 别名]
def port(request):
    """ http://allican.be/blog/2017/01/15/python-dummy-serial-port.html """
    _, slave = pty.openpty()
    return os.ttyname(slave) 
开发者ID:BoboTiG,项目名称:thermalprinter,代码行数:6,代码来源:conftest.py


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