Sophie

Sophie

distrib > Mageia > 6 > armv5tl > by-pkgid > a600cd26dfe6bfd8c11f12bce5cb0eee > files > 907

python3-docs-3.5.3-1.1.mga6.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>35.6. termios — POSIX style tty control &mdash; Python 3.5.3 documentation</title>
    
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.5.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.5.3 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 3.5.3 documentation" href="../contents.html" />
    <link rel="up" title="35. Unix Specific Services" href="unix.html" />
    <link rel="next" title="35.7. tty — Terminal control functions" href="tty.html" />
    <link rel="prev" title="35.5. crypt — Function to check Unix passwords" href="crypt.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    <script type="text/javascript" src="../_static/version_switch.js"></script>
    
    
 

  </head>
  <body role="document">  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="tty.html" title="35.7. tty — Terminal control functions"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="crypt.html" title="35.5. crypt — Function to check Unix passwords"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.5.3</span>
          <a href="../index.html">Documentation </a> &raquo;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">35. Unix Specific Services</a> &raquo;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-termios">
<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>
<hr class="docutils" id="index-0" />
<p>This module provides an interface to the POSIX calls for tty I/O control. For a
complete description of these calls, see <em class="manpage">termios(2)</em> Unix manual
page.  It is only available for those Unix versions that support POSIX
<em>termios</em> style tty I/O control configured during installation.</p>
<p>All functions in this module take a file descriptor <em>fd</em> as their first
argument.  This can be an integer file descriptor, such as returned by
<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>
<p>This module also defines all the constants needed to work with the functions
provided here; these have the same name as their counterparts in C.  Please
refer to your system documentation for more information on using these terminal
control interfaces.</p>
<p>The module defines the following functions:</p>
<dl class="function">
<dt id="termios.tcgetattr">
<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>
<dd><p>Return a list containing the tty attributes for file descriptor <em>fd</em>, as
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
list of the tty special characters (each a string of length 1, except the
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
these fields are defined).  The interpretation of the flags and the speeds as
well as the indexing in the <em>cc</em> array must be done using the symbolic
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>
</dd></dl>

<dl class="function">
<dt id="termios.tcsetattr">
<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>
<dd><p>Set the tty attributes for file descriptor <em>fd</em> from the <em>attributes</em>, which is
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
determines when the attributes are changed: <code class="xref py py-const docutils literal"><span class="pre">TCSANOW</span></code> to change
immediately, <code class="xref py py-const docutils literal"><span class="pre">TCSADRAIN</span></code> to change after transmitting all queued output,
or <code class="xref py py-const docutils literal"><span class="pre">TCSAFLUSH</span></code> to change after transmitting all queued output and
discarding all queued input.</p>
</dd></dl>

<dl class="function">
<dt id="termios.tcsendbreak">
<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>
<dd><p>Send a break on file descriptor <em>fd</em>.  A zero <em>duration</em> sends a break for 0.25
&#8211;0.5 seconds; a nonzero <em>duration</em> has a system dependent meaning.</p>
</dd></dl>

<dl class="function">
<dt id="termios.tcdrain">
<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>
<dd><p>Wait until all output written to file descriptor <em>fd</em> has been transmitted.</p>
</dd></dl>

<dl class="function">
<dt id="termios.tcflush">
<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>
<dd><p>Discard queued data on file descriptor <em>fd</em>.  The <em>queue</em> selector specifies
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
output queue, or <code class="xref py py-const docutils literal"><span class="pre">TCIOFLUSH</span></code> for both queues.</p>
</dd></dl>

<dl class="function">
<dt id="termios.tcflow">
<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>
<dd><p>Suspend or resume input or output on file descriptor <em>fd</em>.  The <em>action</em>
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
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>
</dd></dl>

<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<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>
<dd>Convenience functions for common terminal control operations.</dd>
</dl>
</div>
<div class="section" id="example">
<span id="termios-example"></span><h2>35.6.1. Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<p>Here&#8217;s a function that prompts for a password with echoing turned off.  Note the
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> ...
<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
exactly no matter what happens:</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><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>
    <span class="kn">import</span> <span class="nn">termios</span><span class="o">,</span> <span class="nn">sys</span>
    <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>
    <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>
    <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>
    <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>
    <span class="k">try</span><span class="p">:</span>
        <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>
        <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>
    <span class="k">finally</span><span class="p">:</span>
        <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>
    <span class="k">return</span> <span class="n">passwd</span>
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<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>
<li><a class="reference internal" href="#example">35.6.1. Example</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="crypt.html"
                        title="previous chapter">35.5. <code class="docutils literal"><span class="pre">crypt</span></code> &#8212; Function to check Unix passwords</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="tty.html"
                        title="next chapter">35.7. <code class="docutils literal"><span class="pre">tty</span></code> &#8212; Terminal control functions</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">Report a Bug</a></li>
      <li><a href="../_sources/library/termios.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="tty.html" title="35.7. tty — Terminal control functions"
             >next</a> |</li>
        <li class="right" >
          <a href="crypt.html" title="35.5. crypt — Function to check Unix passwords"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.5.3</span>
          <a href="../index.html">Documentation </a> &raquo;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li class="nav-item nav-item-2"><a href="unix.html" >35. Unix Specific Services</a> &raquo;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 2001-2017, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Jan 20, 2017.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
    </div>

  </body>
</html>