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

📄 module-binascii.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>12.8 binascii -- Convert between binary and ASCII</title>
<META NAME="description" CONTENT="12.8 binascii -- Convert between binary and ASCII">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-xdrlib.html" tppabs="http://www.python.org/doc/current/lib/module-xdrlib.html">
<LINK REL="previous" href="module-uu.html" tppabs="http://www.python.org/doc/current/lib/module-uu.html">
<LINK REL="up" href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html">
<LINK REL="next" href="module-xdrlib.html" tppabs="http://www.python.org/doc/current/lib/module-xdrlib.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-uu.html" tppabs="http://www.python.org/doc/current/lib/module-uu.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-xdrlib.html" tppabs="http://www.python.org/doc/current/lib/module-xdrlib.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-uu.html" tppabs="http://www.python.org/doc/current/lib/module-uu.html">12.7 uu  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html">12. Internet Data Handling</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-xdrlib.html" tppabs="http://www.python.org/doc/current/lib/module-xdrlib.html">12.9 xdrlib  </A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION0014800000000000000000">
12.8 <tt class="module">binascii</tt> --
         Convert between binary and ASCII</A>
</H1>

<P>


<P>
The <tt class="module">binascii</tt> module contains a number of methods to convert
between binary and various ASCII-encoded binary
representations. Normally, you will not use these functions directly
but use wrapper modules like <tt class='module'><a href="module-uu.html" tppabs="http://www.python.org/doc/current/lib/module-uu.html">uu</a></tt> or
<tt class='module'><a href="module-binhex.html" tppabs="http://www.python.org/doc/current/lib/module-binhex.html">binhex</a></tt> instead, this module solely
exists because bit-manipulation of large amounts of data is slow in
Python.

<P>
The <tt class="module">binascii</tt> module defines the following functions:

<P>
<dl><dt><b><a name='l2h-2417'><tt class='function'>a2b_uu</tt></a></b> (<var>string</var>)
<dd>
Convert a single line of uuencoded data back to binary and return the
binary data. Lines normally contain 45 (binary) bytes, except for the
last line. Line data may be followed by whitespace.
</dl>

<P>
<dl><dt><b><a name='l2h-2418'><tt class='function'>b2a_uu</tt></a></b> (<var>data</var>)
<dd>
Convert binary data to a line of ASCII characters, the return value
is the converted line, including a newline char. The length of
<var>data</var> should be at most 45.
</dl>

<P>
<dl><dt><b><a name='l2h-2419'><tt class='function'>a2b_base64</tt></a></b> (<var>string</var>)
<dd>
Convert a block of base64 data back to binary and return the
binary data. More than one line may be passed at a time.
</dl>

<P>
<dl><dt><b><a name='l2h-2420'><tt class='function'>b2a_base64</tt></a></b> (<var>data</var>)
<dd>
Convert binary data to a line of ASCII characters in base64 coding.
The return value is the converted line, including a newline char.
The length of <var>data</var> should be at most 57 to adhere to the base64
standard.
</dl>

<P>
<dl><dt><b><a name='l2h-2421'><tt class='function'>a2b_hqx</tt></a></b> (<var>string</var>)
<dd>
Convert binhex4 formatted ASCII data to binary, without doing
RLE-decompression. The string should contain a complete number of
binary bytes, or (in case of the last portion of the binhex4 data)
have the remaining bits zero.
</dl>

<P>
<dl><dt><b><a name='l2h-2422'><tt class='function'>rledecode_hqx</tt></a></b> (<var>data</var>)
<dd>
Perform RLE-decompression on the data, as per the binhex4
standard. The algorithm uses <code>0x90</code> after a byte as a repeat
indicator, followed by a count. A count of <code>0</code> specifies a byte
value of <code>0x90</code>. The routine returns the decompressed data,
unless data input data ends in an orphaned repeat indicator, in which
case the <tt class="exception">Incomplete</tt> exception is raised.
</dl>

<P>
<dl><dt><b><a name='l2h-2423'><tt class='function'>rlecode_hqx</tt></a></b> (<var>data</var>)
<dd>
Perform binhex4 style RLE-compression on <var>data</var> and return the
result.
</dl>

<P>
<dl><dt><b><a name='l2h-2424'><tt class='function'>b2a_hqx</tt></a></b> (<var>data</var>)
<dd>
Perform hexbin4 binary-to-ASCII translation and return the
resulting string. The argument should already be RLE-coded, and have a
length divisible by 3 (except possibly the last fragment).
</dl>

<P>
<dl><dt><b><a name='l2h-2425'><tt class='function'>crc_hqx</tt></a></b> (<var>data, crc</var>)
<dd>
Compute the binhex4 crc value of <var>data</var>, starting with an initial
<var>crc</var> and returning the result.
</dl>

<P>
<dl><dt><b><a name='l2h-2426'><tt class='function'>crc32</tt></a></b> (<var>data</var><big>[</big><var>, crc</var><big>]</big>)
<dd>
Compute CRC-32, the 32-bit checksum of data, starting with an initial
crc.  This is consistent with the ZIP file checksum.  Use as follows:
<dl><dd><pre class="verbatim">
    print binascii.crc32("hello world")
    # Or, in two pieces:
    crc = binascii.crc32("hello")
    crc = binascii.crc32(" world", crc)
    print crc
</pre></dl>
</dl>

<P>
<dl><dt><b><a name='l2h-2427'><tt class='function'>b2a_hex</tt></a></b> (<var>data</var>)
<dd>
<dt><b><tt class='function'>hexlify</tt></b> (<var>data</var>)
<dd>
Return the hexadecimal representation of the binary <var>data</var>.  Every
byte of <var>data</var> is converted into the corresponding 2-digit hex
representation.  The resulting string is therefore twice as long as
the length of <var>data</var>.
</dl>

<P>
<dl><dt><b><a name='l2h-2428'><tt class='function'>a2b_hex</tt></a></b> (<var>hexstr</var>)
<dd>
<dt><b><tt class='function'>unhexlify</tt></b> (<var>hexstr</var>)
<dd>
Return the binary data represented by the hexadecimal string
<var>hexstr</var>.  This function is the inverse of <tt class="function">b2a_hex()</tt>.
<var>hexstr</var> must contain an even number of hexadecimal digits (which
can be upper or lower case), otherwise a <tt class="exception">TypeError</tt> is
raised.
</dl>

<P>
<dl><dt><b><a name='l2h-2429'><tt class='exception'>Error</tt></a></b>
<dd>
Exception raised on errors. These are usually programming errors.
</dl>

<P>
<dl><dt><b><a name='l2h-2430'><tt class='exception'>Incomplete</tt></a></b>
<dd>
Exception raised on incomplete data. These are usually not programming
errors, but may be handled by reading a little more data and trying
again.
</dl>

<P>
<div class='seealso'>
  <p class='heading'><b>See Also:</b></p>

  <dl compact class="seemodule">
    <dt>Module <b><tt class='module'><a href="module-base64.html" tppabs="http://www.python.org/doc/current/lib/module-base64.html">base64</a></tt>:</b>
    <dd>Support for base64 encoding used in MIME email messages.
  </dl>

<P>
<dl compact class="seemodule">
    <dt>Module <b><tt class='module'><a href="module-binhex.html" tppabs="http://www.python.org/doc/current/lib/module-binhex.html">binhex</a></tt>:</b>
    <dd>Support for the binhex format used on the Macintosh.
  </dl>

<P>
<dl compact class="seemodule">
    <dt>Module <b><tt class='module'><a href="module-uu.html" tppabs="http://www.python.org/doc/current/lib/module-uu.html">uu</a></tt>:</b>
    <dd>Support for UU encoding used on Unix.
  </dl>
</div>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-uu.html" tppabs="http://www.python.org/doc/current/lib/module-uu.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="module-xdrlib.html" tppabs="http://www.python.org/doc/current/lib/module-xdrlib.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-uu.html" tppabs="http://www.python.org/doc/current/lib/module-uu.html">12.7 uu  </A>
<b class="navlabel">Up:</b> <a class="sectref" href="netdata.html" tppabs="http://www.python.org/doc/current/lib/netdata.html">12. Internet Data Handling</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-xdrlib.html" tppabs="http://www.python.org/doc/current/lib/module-xdrlib.html">12.9 xdrlib  </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

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