本文整理汇总了Python中os.ttyname方法的典型用法代码示例。如果您正苦于以下问题:Python os.ttyname方法的具体用法?Python os.ttyname怎么用?Python os.ttyname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.ttyname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stderr
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def test_stderr(self):
# proc.stderr is None in the parent since there is no separate stderr
# stream. In the child, FD 2/stderr is connected to the TTY.
proc, info, buf = run_fd_check(self.func, 2, 'write',
lambda proc: wait_read(proc.stdout, 4))
st = os.fstat(proc.stdout.fileno())
self.assertTrue(stat.S_ISCHR(st.st_mode))
self.assertTrue(stat.S_ISCHR(info['st_mode']))
self.assertTrue(isinstance(info['ttyname'],
mitogen.core.UnicodeType))
self.assertTrue(os.isatty(proc.stdout.fileno()))
flags = fcntl.fcntl(proc.stdout.fileno(), fcntl.F_GETFL)
self.assertTrue(flags & os.O_RDWR)
self.assertTrue(info['flags'] & os.O_RDWR)
self.assertTrue(flags & os.O_RDWR)
self.assertTrue(buf, 'TEST')
示例2: test_baseline_tty_test_code_ttyname_same
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def test_baseline_tty_test_code_ttyname_same():
"""Baseline the ttyname code, ensuring it detects matching ttys."""
master, slave = os.openpty()
subprocess.run(get_python_command(CODE_TTYNAME),
check=True,
shell=True,
stdin=slave,
stdout=slave)
assert os.ttyname(slave) in os.read(master, 100).decode()
示例3: test_baseline_tty_test_code_ttyname_different
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def test_baseline_tty_test_code_ttyname_different():
"""Baseline the ttyname code, ensuring it detects different ttys."""
master, slave = os.openpty()
_, another_slave = os.openpty()
subprocess.run(get_python_command(CODE_TTYNAME),
check=True,
shell=True,
stdin=slave,
stdout=slave)
assert os.ttyname(another_slave) not in os.read(master, 100).decode()
示例4: test_main_run_child_ttyname
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def test_main_run_child_ttyname():
"""Ensure that CT spawns the child in a pseudo-terminal."""
master, slave = os.openpty()
subprocess.run(CLI + ' ' + get_python_command(CODE_TTYNAME),
check=True,
shell=True,
stdin=slave,
stdout=slave)
assert os.ttyname(slave) not in os.read(master, 100).decode()
示例5: main
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def main():
fd = sys.stdin.fileno()
locale.setlocale(locale.LC_ALL, '')
encoding = locale.getpreferredencoding()
print('os.isatty({0}) => {1}'.format(fd, os.isatty(fd)))
print('locale.getpreferredencoding() => {0}'.format(encoding))
display_conf(kind='pathconf',
names=os.pathconf_names,
getter=lambda name: os.fpathconf(fd, name))
try:
(iflag, oflag, cflag, lflag, ispeed, ospeed, cc
) = termios.tcgetattr(fd)
except termios.error as err:
print('stdin is not a typewriter: {0}'.format(err))
else:
display_bitmask(kind='Input Mode',
bitmap=BITMAP_IFLAG,
value=iflag)
display_bitmask(kind='Output Mode',
bitmap=BITMAP_OFLAG,
value=oflag)
display_bitmask(kind='Control Mode',
bitmap=BITMAP_CFLAG,
value=cflag)
display_bitmask(kind='Local Mode',
bitmap=BITMAP_LFLAG,
value=lflag)
display_ctl_chars(index=CTLCHAR_INDEX,
cc=cc)
print('os.ttyname({0}) => {1}'.format(fd, os.ttyname(fd)))
print('os.ctermid() => {0}'.format(os.ttyname(fd)))
示例6: master_open
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def master_open():
"""master_open() -> (master_fd, slave_name)
Open a pty master and return the fd, and the filename of the slave end.
Deprecated, use openpty() instead."""
try:
master_fd, slave_fd = os.openpty()
except (AttributeError, OSError):
pass
else:
slave_name = os.ttyname(slave_fd)
os.close(slave_fd)
return master_fd, slave_name
return _open_terminal()
示例7: fork
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def fork():
"""fork() -> (pid, master_fd)
Fork and make the child a session leader with a controlling terminal."""
try:
pid, fd = os.forkpty()
except (AttributeError, OSError):
pass
else:
if pid == CHILD:
try:
os.setsid()
except OSError:
# os.forkpty() already set us session leader
pass
return pid, fd
master_fd, slave_fd = openpty()
pid = os.fork()
if pid == CHILD:
# Establish a new session.
os.setsid()
os.close(master_fd)
# Slave becomes stdin/stdout/stderr of child.
os.dup2(slave_fd, STDIN_FILENO)
os.dup2(slave_fd, STDOUT_FILENO)
os.dup2(slave_fd, STDERR_FILENO)
if (slave_fd > STDERR_FILENO):
os.close (slave_fd)
# Explicitly open the tty to make it become a controlling tty.
tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR)
os.close(tmp_fd)
else:
os.close(slave_fd)
# Parent and child process.
return pid, master_fd
示例8: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [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)
示例9: getPty
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [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)
示例10: ttyname
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def ttyname(self, fd):
"""
Fake C{os.ttyname}. Return a dumb string.
"""
return "foo"
示例11: pty_make_controlling_tty
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def pty_make_controlling_tty(tty_fd):
'''This makes the pseudo-terminal the controlling tty. This should be
more portable than the pty.fork() function. Specifically, this should
work on Solaris. '''
child_name = os.ttyname(tty_fd)
# Disconnect from controlling tty, if any. Raises OSError of ENXIO
# if there was no controlling tty to begin with, such as when
# executed by a cron(1) job.
try:
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
os.close(fd)
except OSError as err:
if err.errno != errno.ENXIO:
raise
os.setsid()
# Verify we are disconnected from controlling tty by attempting to open
# it again. We expect that OSError of ENXIO should always be raised.
try:
fd = os.open("/dev/tty", os.O_RDWR | os.O_NOCTTY)
os.close(fd)
raise PtyProcessError("OSError of errno.ENXIO should be raised.")
except OSError as err:
if err.errno != errno.ENXIO:
raise
# Verify we can open child pty.
fd = os.open(child_name, os.O_RDWR)
os.close(fd)
# Verify we now have a controlling tty.
fd = os.open("/dev/tty", os.O_WRONLY)
os.close(fd)
示例12: ttyname
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def ttyname(self):
return os.ttyname(self.fileno())
示例13: _tty
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def _tty(self, c):
n = os.ttyname(self._io.fileno())
self._cache[c] = n
return n
示例14: ttyname
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def ttyname(self):
return os.ttyname(self._fo.fileno())
示例15: __str__
# 需要导入模块: import os [as 别名]
# 或者: from os import ttyname [as 别名]
def __str__(self):
if self.deadchild:
return str(self.exitstatus)
else:
st = self.stat()
try:
tty = os.ttyname(self.fileno())
except:
tty = "?"
return "%6d %-7s (%s) %s" % (st.pid, tty, st.statestr(), self.cmdline)