Python pty.openpty() Examples
The following are 30
code examples of pty.openpty().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pty
, or try the search function
.
Example #1
Source File: __init__.py From enlighten with Mozilla Public License 2.0 | 6 votes |
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)
Example #2
Source File: epdb_server.py From epdb with MIT License | 6 votes |
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)
Example #3
Source File: test_ioctl.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: test_ioctl.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #5
Source File: test_ioctl.py From ironpython3 with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: test_ioctl.py From medicare-demo with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: test_ioctl.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: test_ioctl.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #9
Source File: test_ioctl.py From android_universal with MIT License | 6 votes |
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)
Example #10
Source File: test_ioctl.py From oss-ftp with MIT License | 6 votes |
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)
Example #11
Source File: test_ioctl.py From BinderFilter with MIT License | 6 votes |
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)
Example #12
Source File: test_ioctl.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
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)
Example #13
Source File: test_ioctl.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #14
Source File: pydebug.py From kano-toolset with GNU General Public License v2.0 | 6 votes |
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)
Example #15
Source File: epdb_server.py From conary with Apache License 2.0 | 5 votes |
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: 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)
Example #16
Source File: subprocess.py From tbot with GNU General Public License v3.0 | 5 votes |
def __init__(self) -> None: self.pty_master, pty_slave = pty.openpty() self.p = subprocess.Popen( ["bash", "--norc", "--noprofile", "-i"], stdin=pty_slave, stdout=pty_slave, stderr=pty_slave, start_new_session=True, ) flags = fcntl.fcntl(self.pty_master, fcntl.F_GETFL) flags = flags | os.O_NONBLOCK fcntl.fcntl(self.pty_master, fcntl.F_SETFL, flags)
Example #17
Source File: unix.py From python-for-android with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: unix.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
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)
Example #19
Source File: test_driver_pi.py From canute-ui with GNU General Public License v3.0 | 5 votes |
def setUpClass(cls): master, slave = pty.openpty() s_name = os.ttyname(slave) cls._master = master cls._driver = Process(target=Pi, args=(s_name,)) cls._driver.start()
Example #20
Source File: __init__.py From binja_dynamics with Apache License 2.0 | 5 votes |
def __init__(self, message_q): QThread.__init__(self) self.messages = message_q # Only the inferior process need use the slave file descriptor self.master, self.slave = pty.openpty() self.tty = os.ttyname(self.slave)
Example #21
Source File: test_runner.py From imaginary with MIT License | 5 votes |
def makeTerminal(testCase): """ Create a terminal for a given test case. """ leader, follower = pty.openpty() testCase.addCleanup(os.close, leader) testCase.addCleanup(os.close, follower) return leader, follower
Example #22
Source File: ssh_client.py From dcos-e2e with Apache License 2.0 | 5 votes |
def _make_slave_pty(): master_pty, slave_pty = pty.openpty() yield slave_pty os.close(slave_pty) os.close(master_pty)
Example #23
Source File: ssh_client.py From dcos-e2e with Apache License 2.0 | 5 votes |
def _make_slave_pty(): master_pty, slave_pty = pty.openpty() yield slave_pty os.close(slave_pty) os.close(master_pty)
Example #24
Source File: install.py From dockit with GNU General Public License v2.0 | 5 votes |
def execproc(self): logger.debug("Start docker") master, slave = pty.openpty() subprocess.Popen(self.cmd, shell=True, stdin=subprocess.PIPE, stdout=slave, stderr=slave, close_fds=True) # stdout = os.fdopen(master) # logger.debug stdout.readline() time.sleep(10) logger.debug("Checking for successful start of the process") return self.checkproc()
Example #25
Source File: test_tty.py From dockerpty with Apache License 2.0 | 5 votes |
def test_size_returns_a_tuple_for_a_tty(): fd, __ = pty.openpty() fd = os.fdopen(fd) util.set_pty_size(fd, (43, 120)) expect(tty.size(fd)).to(equal((43, 120)))
Example #26
Source File: test_tty.py From dockerpty with Apache License 2.0 | 5 votes |
def test_start_when_raw(self): fd, __ = pty.openpty() terminal = tty.Terminal(os.fdopen(fd), raw=True) expect(israw(fd)).to(be_false) terminal.start() expect(israw(fd)).to(be_true)
Example #27
Source File: test_tty.py From dockerpty with Apache License 2.0 | 5 votes |
def test_start_when_not_raw(self): fd, __ = pty.openpty() terminal = tty.Terminal(os.fdopen(fd), raw=False) expect(israw(fd)).to(be_false) terminal.start() expect(israw(fd)).to(be_false)
Example #28
Source File: test_tty.py From dockerpty with Apache License 2.0 | 5 votes |
def test_stop_when_raw(self): fd, __ = pty.openpty() terminal = tty.Terminal(os.fdopen(fd), raw=True) terminal.start() terminal.stop() expect(israw(fd)).to(be_false)
Example #29
Source File: test_tty.py From dockerpty with Apache License 2.0 | 5 votes |
def test_raw_with_block(self): fd, __ = pty.openpty() fd = os.fdopen(fd) with tty.Terminal(fd, raw=True): expect(israw(fd)).to(be_true) expect(israw(fd)).to(be_false)
Example #30
Source File: terminal.py From moler with BSD 3-Clause "New" or "Revised" License | 5 votes |
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