~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to python-3.5.1-docs-html/library/termios.html

  • Committer: Dave Kuhlman
  • Date: 2017-04-15 16:24:56 UTC
  • Revision ID: dkuhlman@davekuhlman.org-20170415162456-iav9vozzg4iwqwv3
Updated docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
 
 
4
 
 
5
 
<html xmlns="http://www.w3.org/1999/xhtml">
6
 
  <head>
7
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
 
    
9
 
    <title>35.6. termios — POSIX style tty control &mdash; Python 3.5.1 documentation</title>
10
 
    
11
 
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
12
 
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
 
    
14
 
    <script type="text/javascript">
15
 
      var DOCUMENTATION_OPTIONS = {
16
 
        URL_ROOT:    '../',
17
 
        VERSION:     '3.5.1',
18
 
        COLLAPSE_INDEX: false,
19
 
        FILE_SUFFIX: '.html',
20
 
        HAS_SOURCE:  true
21
 
      };
22
 
    </script>
23
 
    <script type="text/javascript" src="../_static/jquery.js"></script>
24
 
    <script type="text/javascript" src="../_static/underscore.js"></script>
25
 
    <script type="text/javascript" src="../_static/doctools.js"></script>
26
 
    <script type="text/javascript" src="../_static/sidebar.js"></script>
27
 
    <link rel="search" type="application/opensearchdescription+xml"
28
 
          title="Search within Python 3.5.1 documentation"
29
 
          href="../_static/opensearch.xml"/>
30
 
    <link rel="author" title="About these documents" href="../about.html" />
31
 
    <link rel="copyright" title="Copyright" href="../copyright.html" />
32
 
    <link rel="top" title="Python 3.5.1 documentation" href="../contents.html" />
33
 
    <link rel="up" title="35. Unix Specific Services" href="unix.html" />
34
 
    <link rel="next" title="35.7. tty — Terminal control functions" href="tty.html" />
35
 
    <link rel="prev" title="35.5. crypt — Function to check Unix passwords" href="crypt.html" />
36
 
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
37
 
    <script type="text/javascript" src="../_static/copybutton.js"></script>
38
 
    <script type="text/javascript" src="../_static/version_switch.js"></script>
39
 
    
40
 
 
41
 
 
42
 
  </head>
43
 
  <body role="document">  
44
 
    <div class="related" role="navigation" aria-label="related navigation">
45
 
      <h3>Navigation</h3>
46
 
      <ul>
47
 
        <li class="right" style="margin-right: 10px">
48
 
          <a href="../genindex.html" title="General Index"
49
 
             accesskey="I">index</a></li>
50
 
        <li class="right" >
51
 
          <a href="../py-modindex.html" title="Python Module Index"
52
 
             >modules</a> |</li>
53
 
        <li class="right" >
54
 
          <a href="tty.html" title="35.7. tty — Terminal control functions"
55
 
             accesskey="N">next</a> |</li>
56
 
        <li class="right" >
57
 
          <a href="crypt.html" title="35.5. crypt — Function to check Unix passwords"
58
 
             accesskey="P">previous</a> |</li>
59
 
        <li><img src="../_static/py.png" alt=""
60
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
61
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
62
 
        <li>
63
 
          <span class="version_switcher_placeholder">3.5.1</span>
64
 
          <a href="../index.html">Documentation </a> &raquo;
65
 
        </li>
66
 
 
67
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
68
 
          <li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">35. Unix Specific Services</a> &raquo;</li> 
69
 
      </ul>
70
 
    </div>    
71
 
 
72
 
    <div class="document">
73
 
      <div class="documentwrapper">
74
 
        <div class="bodywrapper">
75
 
          <div class="body" role="main">
76
 
            
77
 
  <div class="section" id="module-termios">
78
 
<span id="termios-posix-style-tty-control"></span><h1>35.6. <a class="reference internal" href="#module-termios" title="termios: POSIX style tty control. (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">termios</span></code></a> &#8212; POSIX style tty control<a class="headerlink" href="#module-termios" title="Permalink to this headline">¶</a></h1>
79
 
<p id="index-0">This module provides an interface to the POSIX calls for tty I/O control.  For a
80
 
complete description of these calls, see the POSIX or Unix manual pages.  It is
81
 
only available for those Unix versions that support POSIX <em>termios</em> style tty
82
 
I/O control (and then only if configured at installation time).</p>
83
 
<p>All functions in this module take a file descriptor <em>fd</em> as their first
84
 
argument.  This can be an integer file descriptor, such as returned by
85
 
<code class="docutils literal"><span class="pre">sys.stdin.fileno()</span></code>, or a <a class="reference internal" href="../glossary.html#term-file-object"><span class="xref std std-term">file object</span></a>, such as <code class="docutils literal"><span class="pre">sys.stdin</span></code> itself.</p>
86
 
<p>This module also defines all the constants needed to work with the functions
87
 
provided here; these have the same name as their counterparts in C.  Please
88
 
refer to your system documentation for more information on using these terminal
89
 
control interfaces.</p>
90
 
<p>The module defines the following functions:</p>
91
 
<dl class="function">
92
 
<dt id="termios.tcgetattr">
93
 
<code class="descclassname">termios.</code><code class="descname">tcgetattr</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#termios.tcgetattr" title="Permalink to this definition">¶</a></dt>
94
 
<dd><p>Return a list containing the tty attributes for file descriptor <em>fd</em>, as
95
 
follows: <code class="docutils literal"><span class="pre">[iflag,</span> <span class="pre">oflag,</span> <span class="pre">cflag,</span> <span class="pre">lflag,</span> <span class="pre">ispeed,</span> <span class="pre">ospeed,</span> <span class="pre">cc]</span></code> where <em>cc</em> is a
96
 
list of the tty special characters (each a string of length 1, except the
97
 
items with indices <code class="xref py py-const docutils literal"><span class="pre">VMIN</span></code> and <code class="xref py py-const docutils literal"><span class="pre">VTIME</span></code>, which are integers when
98
 
these fields are defined).  The interpretation of the flags and the speeds as
99
 
well as the indexing in the <em>cc</em> array must be done using the symbolic
100
 
constants defined in the <a class="reference internal" href="#module-termios" title="termios: POSIX style tty control. (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">termios</span></code></a> module.</p>
101
 
</dd></dl>
102
 
 
103
 
<dl class="function">
104
 
<dt id="termios.tcsetattr">
105
 
<code class="descclassname">termios.</code><code class="descname">tcsetattr</code><span class="sig-paren">(</span><em>fd</em>, <em>when</em>, <em>attributes</em><span class="sig-paren">)</span><a class="headerlink" href="#termios.tcsetattr" title="Permalink to this definition">¶</a></dt>
106
 
<dd><p>Set the tty attributes for file descriptor <em>fd</em> from the <em>attributes</em>, which is
107
 
a list like the one returned by <a class="reference internal" href="#termios.tcgetattr" title="termios.tcgetattr"><code class="xref py py-func docutils literal"><span class="pre">tcgetattr()</span></code></a>.  The <em>when</em> argument
108
 
determines when the attributes are changed: <code class="xref py py-const docutils literal"><span class="pre">TCSANOW</span></code> to change
109
 
immediately, <code class="xref py py-const docutils literal"><span class="pre">TCSADRAIN</span></code> to change after transmitting all queued output,
110
 
or <code class="xref py py-const docutils literal"><span class="pre">TCSAFLUSH</span></code> to change after transmitting all queued output and
111
 
discarding all queued input.</p>
112
 
</dd></dl>
113
 
 
114
 
<dl class="function">
115
 
<dt id="termios.tcsendbreak">
116
 
<code class="descclassname">termios.</code><code class="descname">tcsendbreak</code><span class="sig-paren">(</span><em>fd</em>, <em>duration</em><span class="sig-paren">)</span><a class="headerlink" href="#termios.tcsendbreak" title="Permalink to this definition">¶</a></dt>
117
 
<dd><p>Send a break on file descriptor <em>fd</em>.  A zero <em>duration</em> sends a break for 0.25
118
 
&#8211;0.5 seconds; a nonzero <em>duration</em> has a system dependent meaning.</p>
119
 
</dd></dl>
120
 
 
121
 
<dl class="function">
122
 
<dt id="termios.tcdrain">
123
 
<code class="descclassname">termios.</code><code class="descname">tcdrain</code><span class="sig-paren">(</span><em>fd</em><span class="sig-paren">)</span><a class="headerlink" href="#termios.tcdrain" title="Permalink to this definition">¶</a></dt>
124
 
<dd><p>Wait until all output written to file descriptor <em>fd</em> has been transmitted.</p>
125
 
</dd></dl>
126
 
 
127
 
<dl class="function">
128
 
<dt id="termios.tcflush">
129
 
<code class="descclassname">termios.</code><code class="descname">tcflush</code><span class="sig-paren">(</span><em>fd</em>, <em>queue</em><span class="sig-paren">)</span><a class="headerlink" href="#termios.tcflush" title="Permalink to this definition">¶</a></dt>
130
 
<dd><p>Discard queued data on file descriptor <em>fd</em>.  The <em>queue</em> selector specifies
131
 
which queue: <code class="xref py py-const docutils literal"><span class="pre">TCIFLUSH</span></code> for the input queue, <code class="xref py py-const docutils literal"><span class="pre">TCOFLUSH</span></code> for the
132
 
output queue, or <code class="xref py py-const docutils literal"><span class="pre">TCIOFLUSH</span></code> for both queues.</p>
133
 
</dd></dl>
134
 
 
135
 
<dl class="function">
136
 
<dt id="termios.tcflow">
137
 
<code class="descclassname">termios.</code><code class="descname">tcflow</code><span class="sig-paren">(</span><em>fd</em>, <em>action</em><span class="sig-paren">)</span><a class="headerlink" href="#termios.tcflow" title="Permalink to this definition">¶</a></dt>
138
 
<dd><p>Suspend or resume input or output on file descriptor <em>fd</em>.  The <em>action</em>
139
 
argument can be <code class="xref py py-const docutils literal"><span class="pre">TCOOFF</span></code> to suspend output, <code class="xref py py-const docutils literal"><span class="pre">TCOON</span></code> to restart
140
 
output, <code class="xref py py-const docutils literal"><span class="pre">TCIOFF</span></code> to suspend input, or <code class="xref py py-const docutils literal"><span class="pre">TCION</span></code> to restart input.</p>
141
 
</dd></dl>
142
 
 
143
 
<div class="admonition seealso">
144
 
<p class="first admonition-title">See also</p>
145
 
<dl class="last docutils">
146
 
<dt>Module <a class="reference internal" href="tty.html#module-tty" title="tty: Utility functions that perform common terminal control operations. (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">tty</span></code></a></dt>
147
 
<dd>Convenience functions for common terminal control operations.</dd>
148
 
</dl>
149
 
</div>
150
 
<div class="section" id="example">
151
 
<span id="termios-example"></span><h2>35.6.1. Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
152
 
<p>Here&#8217;s a function that prompts for a password with echoing turned off.  Note the
153
 
technique using a separate <a class="reference internal" href="#termios.tcgetattr" title="termios.tcgetattr"><code class="xref py py-func docutils literal"><span class="pre">tcgetattr()</span></code></a> call and a <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal"><span class="pre">try</span></code></a> ...
154
 
<a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal"><span class="pre">finally</span></code></a> statement to ensure that the old tty attributes are restored
155
 
exactly no matter what happens:</p>
156
 
<div class="highlight-python3"><div class="highlight"><pre><span class="k">def</span> <span class="nf">getpass</span><span class="p">(</span><span class="n">prompt</span><span class="o">=</span><span class="s2">&quot;Password: &quot;</span><span class="p">):</span>
157
 
    <span class="kn">import</span> <span class="nn">termios</span><span class="o">,</span> <span class="nn">sys</span>
158
 
    <span class="n">fd</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">fileno</span><span class="p">()</span>
159
 
    <span class="n">old</span> <span class="o">=</span> <span class="n">termios</span><span class="o">.</span><span class="n">tcgetattr</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>
160
 
    <span class="n">new</span> <span class="o">=</span> <span class="n">termios</span><span class="o">.</span><span class="n">tcgetattr</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span>
161
 
    <span class="n">new</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="n">new</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">termios</span><span class="o">.</span><span class="n">ECHO</span>          <span class="c1"># lflags</span>
162
 
    <span class="k">try</span><span class="p">:</span>
163
 
        <span class="n">termios</span><span class="o">.</span><span class="n">tcsetattr</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span> <span class="n">termios</span><span class="o">.</span><span class="n">TCSADRAIN</span><span class="p">,</span> <span class="n">new</span><span class="p">)</span>
164
 
        <span class="n">passwd</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="n">prompt</span><span class="p">)</span>
165
 
    <span class="k">finally</span><span class="p">:</span>
166
 
        <span class="n">termios</span><span class="o">.</span><span class="n">tcsetattr</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span> <span class="n">termios</span><span class="o">.</span><span class="n">TCSADRAIN</span><span class="p">,</span> <span class="n">old</span><span class="p">)</span>
167
 
    <span class="k">return</span> <span class="n">passwd</span>
168
 
</pre></div>
169
 
</div>
170
 
</div>
171
 
</div>
172
 
 
173
 
 
174
 
          </div>
175
 
        </div>
176
 
      </div>
177
 
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
178
 
        <div class="sphinxsidebarwrapper">
179
 
  <h3><a href="../contents.html">Table Of Contents</a></h3>
180
 
  <ul>
181
 
<li><a class="reference internal" href="#">35.6. <code class="docutils literal"><span class="pre">termios</span></code> &#8212; POSIX style tty control</a><ul>
182
 
<li><a class="reference internal" href="#example">35.6.1. Example</a></li>
183
 
</ul>
184
 
</li>
185
 
</ul>
186
 
 
187
 
  <h4>Previous topic</h4>
188
 
  <p class="topless"><a href="crypt.html"
189
 
                        title="previous chapter">35.5. <code class="docutils literal"><span class="pre">crypt</span></code> &#8212; Function to check Unix passwords</a></p>
190
 
  <h4>Next topic</h4>
191
 
  <p class="topless"><a href="tty.html"
192
 
                        title="next chapter">35.7. <code class="docutils literal"><span class="pre">tty</span></code> &#8212; Terminal control functions</a></p>
193
 
<h3>This Page</h3>
194
 
<ul class="this-page-menu">
195
 
  <li><a href="../bugs.html">Report a Bug</a></li>
196
 
  <li><a href="../_sources/library/termios.txt"
197
 
         rel="nofollow">Show Source</a></li>
198
 
</ul>
199
 
 
200
 
<div id="searchbox" style="display: none" role="search">
201
 
  <h3>Quick search</h3>
202
 
    <form class="search" action="../search.html" method="get">
203
 
      <input type="text" name="q" />
204
 
      <input type="submit" value="Go" />
205
 
      <input type="hidden" name="check_keywords" value="yes" />
206
 
      <input type="hidden" name="area" value="default" />
207
 
    </form>
208
 
    <p class="searchtip" style="font-size: 90%">
209
 
    Enter search terms or a module, class or function name.
210
 
    </p>
211
 
</div>
212
 
<script type="text/javascript">$('#searchbox').show(0);</script>
213
 
        </div>
214
 
      </div>
215
 
      <div class="clearer"></div>
216
 
    </div>  
217
 
    <div class="related" role="navigation" aria-label="related navigation">
218
 
      <h3>Navigation</h3>
219
 
      <ul>
220
 
        <li class="right" style="margin-right: 10px">
221
 
          <a href="../genindex.html" title="General Index"
222
 
             >index</a></li>
223
 
        <li class="right" >
224
 
          <a href="../py-modindex.html" title="Python Module Index"
225
 
             >modules</a> |</li>
226
 
        <li class="right" >
227
 
          <a href="tty.html" title="35.7. tty — Terminal control functions"
228
 
             >next</a> |</li>
229
 
        <li class="right" >
230
 
          <a href="crypt.html" title="35.5. crypt — Function to check Unix passwords"
231
 
             >previous</a> |</li>
232
 
        <li><img src="../_static/py.png" alt=""
233
 
                 style="vertical-align: middle; margin-top: -1px"/></li>
234
 
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
235
 
        <li>
236
 
          <span class="version_switcher_placeholder">3.5.1</span>
237
 
          <a href="../index.html">Documentation </a> &raquo;
238
 
        </li>
239
 
 
240
 
          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
241
 
          <li class="nav-item nav-item-2"><a href="unix.html" >35. Unix Specific Services</a> &raquo;</li> 
242
 
      </ul>
243
 
    </div>  
244
 
    <div class="footer">
245
 
    &copy; <a href="../copyright.html">Copyright</a> 1990-2016, Python Software Foundation.
246
 
    <br />
247
 
    The Python Software Foundation is a non-profit corporation.
248
 
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
249
 
    <br />
250
 
    Last updated on Jan 22, 2016.
251
 
    <a href="../bugs.html">Found a bug</a>?
252
 
    <br />
253
 
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
254
 
    </div>
255
 
 
256
 
  </body>
257
 
</html>
 
 
b'\\ No newline at end of file'