Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libtermios.tex @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | dbb41712165b |
| children | b218f294b726 |
| rev | line source |
|---|---|
|
2609
7ef72873e4d6
restructured library manual accordiung to functional group
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 \section{Built-in Module \sectcode{termios}} |
|
2626
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
2 \bimodindex{termios} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
3 \indexii{Posix}{I/O control} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
4 \indexii{tty}{I/O control} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
5 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
6 \renewcommand{\indexsubitem}{(in module termios)} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
7 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
8 This module provides an interface to the Posix calls for tty I/O |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
9 control. For a complete description of these calls, see the Posix or |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
10 \UNIX{} manual pages. It is only available for those \UNIX{} versions |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
11 that support Posix \code{termios} style tty I/O control (and then |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
12 only if configured at installation time). |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
13 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
14 All functions in this module take a file descriptor \var{fd} as their |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
15 first argument. This must be an integer file descriptor, such as |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
16 returned by \code{sys.stdin.fileno()}. |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
17 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
18 This module should be used in conjunction with the \code{TERMIOS} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
19 module, which defines the relevant symbolic constants (see the next |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
20 section). |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
21 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
22 The module defines the following functions: |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
23 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
24 \begin{funcdesc}{tcgetattr}{fd} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
25 Return a list containing the tty attributes for file descriptor |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
26 \var{fd}, as follows: \code{[\var{iflag}, \var{oflag}, \var{cflag}, |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
27 \var{lflag}, \var{ispeed}, \var{ospeed}, \var{cc}]} where \var{cc} is |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
28 a list of the tty special characters (each a string of length 1, |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
29 except the items with indices \code{VMIN} and \code{VTIME}, which are |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
30 integers when these fields are defined). The interpretation of the |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
31 flags and the speeds as well as the indexing in the \var{cc} array |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
32 must be done using the symbolic constants defined in the |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
33 \code{TERMIOS} module. |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
34 \end{funcdesc} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
35 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
36 \begin{funcdesc}{tcsetattr}{fd\, when\, attributes} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
37 Set the tty attributes for file descriptor \var{fd} from the |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
38 \var{attributes}, which is a list like the one returned by |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
39 \code{tcgetattr()}. The \var{when} argument determines when the |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
40 attributes are changed: \code{TERMIOS.TCSANOW} to change immediately, |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
41 \code{TERMIOS.TCSADRAIN} to change after transmitting all queued |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
42 output, or \code{TERMIOS.TCSAFLUSH} to change after transmitting all |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
43 queued output and discarding all queued input. |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
44 \end{funcdesc} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
45 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
46 \begin{funcdesc}{tcsendbreak}{fd\, duration} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
47 Send a break on file descriptor \var{fd}. A zero \var{duration} sends |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
48 a break for 0.25--0.5 seconds; a nonzero \var{duration} has a system |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
49 dependent meaning. |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
50 \end{funcdesc} |
|
2609
7ef72873e4d6
restructured library manual accordiung to functional group
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 |
|
2626
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
52 \begin{funcdesc}{tcdrain}{fd} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
53 Wait until all output written to file descriptor \var{fd} has been |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
54 transmitted. |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
55 \end{funcdesc} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
56 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
57 \begin{funcdesc}{tcflush}{fd\, queue} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
58 Discard queued data on file descriptor \var{fd}. The \var{queue} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
59 selector specifies which queue: \code{TERMIOS.TCIFLUSH} for the input |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
60 queue, \code{TERMIOS.TCOFLUSH} for the output queue, or |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
61 \code{TERMIOS.TCIOFLUSH} for both queues. |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
62 \end{funcdesc} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
63 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
64 \begin{funcdesc}{tcflow}{fd\, action} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
65 Suspend or resume input or output on file descriptor \var{fd}. The |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
66 \var{action} argument can be \code{TERMIOS.TCOOFF} to suspend output, |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
67 \code{TERMIOS.TCOON} to restart output, \code{TERMIOS.TCIOFF} to |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
68 suspend input, or \code{TERMIOS.TCION} to restart input. |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
69 \end{funcdesc} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
70 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
71 \subsection{Example} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
72 \nodename{termios Example} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
73 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
74 Here's a function that prompts for a password with echoing turned off. |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
75 Note the technique using a separate \code{termios.tcgetattr()} call |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
76 and a \code{try {\ldots} finally} statement to ensure that the old tty |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
77 attributes are restored exactly no matter what happens: |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
78 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
79 \begin{verbatim} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
80 def getpass(prompt = "Password: "): |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
81 import termios, TERMIOS, sys |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
82 fd = sys.stdin.fileno() |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
83 old = termios.tcgetattr(fd) |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
84 new = termios.tcgetattr(fd) |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
85 new[3] = new[3] & ~TERMIOS.ECHO # lflags |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
86 try: |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
87 termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new) |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
88 passwd = raw_input(prompt) |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
89 finally: |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
90 termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old) |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
91 return passwd |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
92 \end{verbatim} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
93 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
94 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
95 \section{Standard Module \sectcode{TERMIOS}} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
96 \stmodindex{TERMIOS} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
97 \indexii{Posix}{I/O control} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
98 \indexii{tty}{I/O control} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
99 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
100 \renewcommand{\indexsubitem}{(in module TERMIOS)} |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
101 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
102 This module defines the symbolic constants required to use the |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
103 \code{termios} module (see the previous section). See the Posix or |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
104 \UNIX{} manual pages (or the source) for a list of those constants. |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
105 |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
106 Note: this module resides in a system-dependent subdirectory of the |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
107 Python library directory. You may have to generate it for your |
|
dbb41712165b
documented termios + TERMIOS
Guido van Rossum <guido@python.org>
parents:
2609
diff
changeset
|
108 particular system using the script \file{Tools/scripts/h2py.py}. |
