當前位置: 首頁>>代碼示例>>Python>>正文


Python os.ttyname方法代碼示例

本文整理匯總了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') 
開發者ID:dw,項目名稱:mitogen,代碼行數:22,代碼來源:create_child_test.py

示例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() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:13,代碼來源:test_cli.py

示例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() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:14,代碼來源:test_cli.py

示例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() 
開發者ID:hSaria,項目名稱:ChromaTerm,代碼行數:12,代碼來源:test_cli.py

示例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))) 
開發者ID:HoussemCharf,項目名稱:FunUtils,代碼行數:36,代碼來源:display-terminal-info.py

示例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() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:pty.py

示例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 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:41,代碼來源:pty.py

示例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) 
開發者ID:Ousret,項目名稱:pyTeliumManager,代碼行數:9,代碼來源:test_tpe.py

示例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) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:10,代碼來源:unix.py

示例10: ttyname

# 需要導入模塊: import os [as 別名]
# 或者: from os import ttyname [as 別名]
def ttyname(self, fd):
        """
        Fake C{os.ttyname}. Return a dumb string.
        """
        return "foo" 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_process.py

示例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) 
開發者ID:pypa,項目名稱:pipenv,代碼行數:38,代碼來源:_fork_pty.py

示例12: ttyname

# 需要導入模塊: import os [as 別名]
# 或者: from os import ttyname [as 別名]
def ttyname(self):
        return os.ttyname(self.fileno()) 
開發者ID:kdart,項目名稱:pycopia,代碼行數:4,代碼來源:UserFile.py

示例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 
開發者ID:kdart,項目名稱:pycopia,代碼行數:6,代碼來源:UI.py

示例14: ttyname

# 需要導入模塊: import os [as 別名]
# 或者: from os import ttyname [as 別名]
def ttyname(self):
        return os.ttyname(self._fo.fileno()) 
開發者ID:kdart,項目名稱:pycopia,代碼行數:4,代碼來源:expect.py

示例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) 
開發者ID:kdart,項目名稱:pycopia,代碼行數:12,代碼來源:proctools.py


注:本文中的os.ttyname方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。