uTools-Manuals/docs/python/getpass.html
2019-04-08 23:22:26 +08:00

1 line
4.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="body" role="main"><div class="section" id="module-getpass"><h1><span class="yiyi-st" id="yiyi-10">16.9. <a class="reference internal" href="#module-getpass" title="getpass: Portable reading of passwords and retrieval of the userid."><code class="xref py py-mod docutils literal"><span class="pre">getpass</span></code></a> - 便携式密码输入</span></h1><p><span class="yiyi-st" id="yiyi-11"><strong>源代码:</strong> <a class="reference external" href="https://hg.python.org/cpython/file/3.5/Lib/getpass.py">Lib / getpass.py</a></span></p><p><span class="yiyi-st" id="yiyi-12"><a class="reference internal" href="#module-getpass" title="getpass: Portable reading of passwords and retrieval of the userid."><code class="xref py py-mod docutils literal"><span class="pre">getpass</span></code></a>模块提供两个功能</span></p><dl class="function"><dt id="getpass.getpass"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">getpass.</code><code class="descname">getpass</code><span class="sig-paren">(</span><em>prompt='Password: '</em>, <em>stream=None</em><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-14">提示用户输入密码,而不回显。</span><span class="yiyi-st" id="yiyi-15">将使用字符串<em>提示</em>提示用户,其默认为<code class="docutils literal"><span class="pre">“密码:</span> <span class="pre">'</span></code></span><span class="yiyi-st" id="yiyi-16">在Unix上如果需要使用replace错误处理程序将提示写入类似文件的对象<em>stream</em></span><span class="yiyi-st" id="yiyi-17"><em>stream</em>默认为控制终端(<code class="file docutils literal"><span class="pre">/dev/tty</span></code>)或<code class="docutils literal"><span class="pre">sys.stderr</span></code>不可用在Windows上忽略此参数</span></p><p><span class="yiyi-st" id="yiyi-18">如果无回显输入不可用getpass()回到向<em>stream</em>打印警告消息并从<code class="docutils literal"><span class="pre">sys.stdin</span></code>读取并发出<a class="reference internal" href="#getpass.GetPassWarning" title="getpass.GetPassWarning"><code class="xref py py-exc docutils literal"><span class="pre">GetPassWarning</span></code></a></span></p><div class="admonition note"><p class="first admonition-title"><span class="yiyi-st" id="yiyi-19">注意</span></p><p class="last"><span class="yiyi-st" id="yiyi-20">如果在IDLE中调用getpass则输入可以在启动IDLE的终端中完成而不是IDLE窗口本身。</span></p></div></dd></dl><dl class="exception"><dt id="getpass.GetPassWarning"><span class="yiyi-st" id="yiyi-21"> <em class="property">exception </em><code class="descclassname">getpass.</code><code class="descname">GetPassWarning</code></span></dt><dd><p><span class="yiyi-st" id="yiyi-22">当密码输入可能被回显时,发出<a class="reference internal" href="exceptions.html#UserWarning" title="UserWarning"><code class="xref py py-exc docutils literal"><span class="pre">UserWarning</span></code></a>子类。</span></p></dd></dl><dl class="function"><dt id="getpass.getuser"><span class="yiyi-st" id="yiyi-23"> <code class="descclassname">getpass.</code><code class="descname">getuser</code><span class="sig-paren">(</span><span class="sig-paren">)</span></span></dt><dd><p><span class="yiyi-st" id="yiyi-24">返回用户的“登录名”。</span></p><p><span class="yiyi-st" id="yiyi-25">这个函数依次将检查<span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal"><span class="pre">LOGNAME</span></code>, <span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal"><span class="pre">USER</span></code>, <span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal"><span class="pre">LNAME</span></code><span class="target" id="index-3"></span><code class="xref std std-envvar docutils literal"><span class="pre">USERNAME</span></code>环境变量,然后返回检测到的第一个非空字符串。</span><span class="yiyi-st" id="yiyi-26">如果没有设置,则在支持<a class="reference internal" href="pwd.html#module-pwd" title="pwd: The password database (getpwnam() and friends). (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">pwd</span></code></a>模块的系统上返回密码数据库中的登录名,否则会引发异常。</span></p></dd></dl></div></div>