⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 117.html

📁 国外python经典教材,python爱好者的首选
💻 HTML
📖 第 1 页 / 共 2 页
字号:
========================== 
getservbyname     gethostbyaddr   htons           socket 
ntohs             gethostbyname   fromfd          getprotobyname 
gethostname       htonl 
Undocumented commands: 
====================== 
EOF              help 
?>> help socket 
socket(family, type[, proto]) -> socket object 
Open a socket of the given type.  The family argument 
specifies the address family; it is normally AF_INET, 
sometimes AF_Unix.  The type argument specifies whether this 
is a stream (SOCK_STREAM) or datagram (SOCK_DGRAM) socket. 
The protocol argument defaults to 0, specifying the default 
protocol. 
?>> s = socket(AF_INET, SOCK_STREAM) 
?>> s.connect("www.python.org",80) 
... </PRe>

<p>? <b>See Also</b> <A HREf="117#16.html">shlex</a> (288).</p>

<a name="8"></a>
<h4><tt class="monofont">md5</tt></h4>
<P>The <tt ClasS="monofont">md5</tt>  module implements RSA抯 MD5 message-digest algorithm. MD5 takes a sequence of input text and produces a 128-bit hash value. To compute the hash value, create an <tt ClasS="monofont">md5</TT>  object using the <Tt claSS="monofont">new()</TT> function, feed data to it using the <tt clASS="monofont">update()</Tt> method, and then call the <tt cLASS="monofont">digest()</tt> method to get the hash value.</p>

<pre>

<b>new([</b><b><i>arg</i></b><b>])</b> </pre>

<p>Returns a new <tt ClaSs="monofont">md5</tt>  object. If <I><tt clAss="monofont">arg</tT></I>
 is present, the method call <TT clasS="monofont">update(</TT><I><tt clASS="monofont">arg</Tt></i>
<tt CLASs="monofont">)</tt> is also made.</p>

<p>An <tt class="monofont">md5</tt>  object <i><tt claSs="monofont">m</tT></i>
 has the following methods:</p>

<pRe>

<b><i>m</i></B><b>.update(</b><b><I>arg</I></B><B>)</b> </pre>

<P>Updates the <TT Class="monofont">md5</TT>  object <I><Tt claSS="monofont">m</TT></i>
 with the string <i><tt class="monofont">arg</tt></i>
. Repeated calls are equivalent to a single call with the concatenation of all the arguments.</p>

<pre>

<b><i>m</i></b><B>.digest()</b> </pRe>

<p>Returns the digest of all data passed to the object using the <tT clasS="monofont">update()</tt> method so far. Returns a 16-byte string that may contain nonprintable characters, including null bytes.</p>

<PRE>

<B><i>m</i></b><b>.copy()</B> </PRE>

<p>Returns a copy of the <tt cLASS="monofont">md5</tt>  object.</p>


<h5>Example</H5>
<PRE>

import md5 
m = md5.new()            # Create a new MD5 object 
m.update("Hello") 
m.update("World") 
d = m.digest()           # Get the digest </pre>

<p>The following shortcut can also be used:</p>

<pre>

d = md5.new("Hello World").digest() </pre>

<p>? <b>See Also</b> <a href="117#12.html">sha</a> (287), Internet RFC 1321.</P>

<a nAme="12"></a>
<H4><tt clAss="monofont">sha</tT></H4>
<P>The <Tt claSS="monofont">sha</TT>  module implements the secure hash algorithm (SHA). SHA takes a sequence of input text and produces a 160-bit hash value. To compute the hash value, create an <tt clASS="monofont">sha</Tt>  object using the <tt cLASS="monofont">new()</tt> function and feed data to it.</p>

<pre>

<b>new([</b><b><i>string</i></b><b>])</b> </pre>

<p>Returns a new <tt ClaSs="monofont">sha</tt>  object. If <I><tt clAss="monofont">string</tT></I>
 is present, the method call <TT clasS="monofont">update(</TT><I><tt clASS="monofont">string</Tt></i>
<tt CLASs="monofont">)</tt> is made.</p>

<pre>

<b>blocksize</b> </pre>

<p>Size of the blocks fed into the hash function. This is always <tt class="monofont">1</Tt>.</p>

<Pre>

<b>digestsize</B> </pre>

<p>The size of the resulting digest in bytes. This is always <Tt clASS="monofont">20</Tt>.</p>

<p>An instance <i><TT CLass="monofont">s</tT></I>
 of an <TT clasS="monofont">sha</TT> object has the following methods:</P>

<pre>

<b><i>s</i></b><b>.update(</b><b><i>arg</i></b><b>)</b> </pre>

<p>Updates the <tT clAss="monofont">sha</tT>  object with the string <i><tt cLass="monofont">arg</TT></I>
. Repeated calls are equivalent to a single call with the concatenation of all the arguments.</P>

<pre>

<b><I>s</I></B><B>.digest()</b> </pre>

<P>Returns the digest of all data passed to the object using the <TT Class="monofont">update()</TT> method so far. Returns a 20-byte string that may contain nonprintable characters, including null bytes.</P>

<Pre>

<b><i>s</i></b><b>.copy()</b> </pre>

<p>Returns a copy of the <tt class="monofont">sha</tT>  object.</p>

<pRe>

<b><i>s</I></b><b>.hexdigest()</b> </pRe>

<p>Returns the digest value as a string of hexadecimal digits.</p>


<H5>Note</H5>
<UL>
<li>
<p>The SHA algorithm is defined by NIST document FIPS PUB 180-1: Secure Hash Standard. It抯 available online at <a TARGet="_blank" hrEF="http://csrc.nist.gov/fips/fip180-1.ps">http://csrc.nist.gov/fips/fip180-1.ps</A>.</P>
</li>
</ul>
<P>? <B>See Also</B> <A href="117#8.html">md5</a> (286).</p>

<a name="16"></a>
<h4><tt class="monofont">shlex</Tt></h4>
<P>The <tt cLass="monofont">shlex</tT>  module provides a class <tt cLASS="monofont">shlex</tt>  that can be used to build lexical analyzers for simple syntaxes such as shells.</p>

<pRE>

<B>shlex([</B><b><i>stream</i></b><B>])</B> </PRe>

<p>Creates an instance of the <tt CLASs="monofont">shlex</tt>  class. <i><tt class="monofont">stream</tt></i>
 specifies a file or stream-like object where characters will be read. This object must provide <tt clasS="monofont">read()</tt> and <Tt clAss="monofont">readline()</tt> methods. If omitted, input is taken from <Tt clASS="monofont">sys.stdin</Tt>.</p>

<p>An instance <i><TT CLass="monofont">s</tT></I>
 of the <TT clasS="monofont">shlex</TT> class supports the following methods:</P>

<pre>

<b><i>s</i></b><b>.get_token()</b> </pre>

<p>Returns a token (as a string). If tokens have been saved with <tt class="monofont">push_token()</Tt>, a token is popped off the stack. Otherwise, the token is read from the input stream. An end-of-file returns an empty string.</p>

<Pre>

<b><I>s</i></b><b>.push_token(</b><B><i>str</i></b><B>)</B> </PRe>

<p>Pushes a token onto the token stack.</p>

<p>In addition, the following instance variables can be set:</P>

<P><TAble bORDEr="1" celLSPAcing="0" cellpadding="1" width="100%">
<ColGrouP span="2">
<Tr>
<th VALIgn="top">
<foNT SIze="2">
<p><b>Variable</B></P>
</FOnt></th>
<TH VAlign="top">
<font size="2">
<p><b>Description</b></p>
</font></Th>
</tR>
<tr>
<tD valiGn="top">
<foNT SIze="2">
<p><i><TT CLass="monofont">s</tT></I>
<TT clasS="monofont">.commenters</TT></P>
</font></td>
<td valign="top">
<font siZe="2">
<p>String of characters recognized as starting a comment. Comments continue to the end of the line. Includes <Tt clAss="monofont">'#'</tt> by default.</P>
</fonT></TD>
</Tr>
<tr>
<tD VALign="top">
<fONT Size="2">
<p><I><TT Class="monofont">s</tt></i>
<tt class="monofont">.wordchars</tt></p>
</fonT></td>
<Td vaLign="top">
<fOnt sIZE="2">
<P>String of characters that form multi-character tokens. Includes all ASCII alphanumeric characters and the underscore by default.</p>
</fonT></TD>
</Tr>
<tr>
<tD VALign="top">
<fONT Size="2">
<p><i><tt class="monofont">s</tt></i>
<tt claSs="monofont">.whitespace</tT></p>
</foNt></td>
<tD valIGN="top">
<Font sIZE="2">
<P>String of whitespace characters that will be skipped.</p>
</fonT></TD>
</Tr>
<tr>
<tD VALign="top">
<font size="2">
<p><i><tt class="monofont">s</Tt></i>
<Tt clAss="monofont">.quotes</tt></P>
</fonT></TD>
<Td valIGN="top">
<Font sIZE="2">
<P>Characters that will be considered to be string quotes. Includes single and double quotes by default.</p>
</fonT></TD>
</Tr>
<tr>
<td valign="top">
<font size="2">
<p><I><tt ClasS="monofont">s</tt></i>
<tT claSS="monofont">.lineno</TT></p>
</fonT></TD>
<Td valIGN="top">
<Font sIZE="2">
<P>Source line number.</p>
</font></td>
</tr>
<tr>
<td valign="top">
<fOnt Size="2">
<P><i><tt cLass="monofont">s</TT></I>
<Tt claSS="monofont">.token</TT></p>
</fonT></TD>
<Td valIGN="top">
<Font size="2">
<p>The token buffer.</p>
</font></td>
</tr>
</colGroUp>
</taBle></p>


<h5>Note</H5>
<ul>
<lI>
<P>Any character not declared to be a word character, whitespace, or a quote is returned as a single-character token. Also, words must be delimited by whitespace. Special symbols such as quotes and comments are not recognized within words. Thus, a word such as <TT clasS="monofont">isn't</TT>  is returned as a single token.</P>
</li>
</ul>
<P>? <B>See Also</B> <A href="117#4.html">cmd</A> (284).</P>
</FOnt>
<P><TABLE width="100%" border=0><TR valign="top"><TD><font size=1 color="#C0C0C0"><br></font></TD><TD align=right><font size=1 color="#C0C0C0">Last updated on 3/28/2002<br>Python Essential Reference, Second Edition, &copy;&nbsp;2002 New Riders Publishing</font></TD></TR></TABLE></P>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="116.html" title="Restricted Execution"><font size="1">&lt;&nbsp;BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0735710910&snode=117" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="117.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="118.html" title="The Python Debugger"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
</TD></TR></TABLE>




<!--EndOfBrowse-->

</TD></TR></TABLE>
<table width=100% border=0 cellspacing=0 cellpadding=0 bgcolor=#990000><tr><td><p align=center><font size=1 face="verdana,arial,helvetica" color=white>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -