Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > e1011ddec34cda34f3a002b121247943 > files > 947

python-docs-2.7.17-1.1.mga7.noarch.rpm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>36.7. termios — POSIX style tty control &#8212; Python 2.7.17 documentation</title>
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></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/language_data.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 2.7.17 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="next" title="36.8. tty — Terminal control functions" href="tty.html" />
    <link rel="prev" title="36.6. dl — Call C functions in shared objects" href="dl.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/2/library/termios.html" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
 
    

  </head><body>  
    <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="36.8. tty — Terminal control functions"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="dl.html" title="36.6. dl — Call C functions in shared objects"
             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> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.17 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">36. Unix Specific Services</a> &#187;</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>36.7. <a class="reference internal" href="#module-termios" title="termios: POSIX style tty control. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">termios</span></code></a> — POSIX style tty control<a class="headerlink" href="#module-termios" title="Permalink to this headline">¶</a></h1>
<p id="index-0">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 notranslate"><span class="pre">sys.stdin.fileno()</span></code>, or a file object, such as <code class="docutils literal notranslate"><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 notranslate"><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 notranslate"><span class="pre">VMIN</span></code> and <code class="xref py py-const docutils literal notranslate"><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 notranslate"><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 notranslate"><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 notranslate"><span class="pre">TCSANOW</span></code> to change
immediately, <code class="xref py py-const docutils literal notranslate"><span class="pre">TCSADRAIN</span></code> to change after transmitting all queued output,
or <code class="xref py py-const docutils literal notranslate"><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
–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 notranslate"><span class="pre">TCIFLUSH</span></code> for the input queue, <code class="xref py py-const docutils literal notranslate"><span class="pre">TCOFLUSH</span></code> for the
output queue, or <code class="xref py py-const docutils literal notranslate"><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 notranslate"><span class="pre">TCOOFF</span></code> to suspend output, <code class="xref py py-const docutils literal notranslate"><span class="pre">TCOON</span></code> to restart
output, <code class="xref py py-const docutils literal notranslate"><span class="pre">TCIOFF</span></code> to suspend input, or <code class="xref py py-const docutils literal notranslate"><span class="pre">TCION</span></code> to restart input.</p>
</dd></dl>

<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<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 notranslate"><span class="pre">tty</span></code></a></dt><dd><p>Convenience functions for common terminal control operations.</p>
</dd>
</dl>
</div>
<div class="section" id="example">
<h2>36.7.1. Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<p id="termios-example">Here’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 notranslate"><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 notranslate"><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 notranslate"><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-default notranslate"><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="n">raw_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="#">36.7. <code class="xref py py-mod docutils literal notranslate"><span class="pre">termios</span></code> — POSIX style tty control</a><ul>
<li><a class="reference internal" href="#example">36.7.1. Example</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="dl.html"
                        title="previous chapter">36.6. <code class="xref py py-mod docutils literal notranslate"><span class="pre">dl</span></code> — Call C functions in shared objects</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="tty.html"
                        title="next chapter">36.8. <code class="xref py py-mod docutils literal notranslate"><span class="pre">tty</span></code> — Terminal control functions</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/library/termios.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </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="36.8. tty — Terminal control functions"
             >next</a> |</li>
        <li class="right" >
          <a href="dl.html" title="36.6. dl — Call C functions in shared objects"
             >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> &#187;</li>
        <li>
          <a href="../index.html">Python 2.7.17 documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="unix.html" >36. Unix Specific Services</a> &#187;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2019, 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 Oct 19, 2019.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
    </div>

  </body>
</html>