summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Fbinascii.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/python~3.12/library%2Fbinascii.html
new repository
Diffstat (limited to 'devdocs/python~3.12/library%2Fbinascii.html')
-rw-r--r--devdocs/python~3.12/library%2Fbinascii.html70
1 files changed, 70 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Fbinascii.html b/devdocs/python~3.12/library%2Fbinascii.html
new file mode 100644
index 00000000..d50bc961
--- /dev/null
+++ b/devdocs/python~3.12/library%2Fbinascii.html
@@ -0,0 +1,70 @@
+ <span id="binascii-convert-between-binary-and-ascii"></span><h1>binascii — Convert between binary and ASCII</h1> <p>The <a class="reference internal" href="#module-binascii" title="binascii: Tools for converting between binary and various ASCII-encoded binary representations."><code>binascii</code></a> 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 <a class="reference internal" href="uu#module-uu" title="uu: Encode and decode files in uuencode format. (deprecated)"><code>uu</code></a> or <a class="reference internal" href="base64#module-base64" title="base64: RFC 4648: Base16, Base32, Base64 Data Encodings; Base85 and Ascii85"><code>base64</code></a> instead. The <a class="reference internal" href="#module-binascii" title="binascii: Tools for converting between binary and various ASCII-encoded binary representations."><code>binascii</code></a> module contains low-level functions written in C for greater speed that are used by the higher-level modules.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p><code>a2b_*</code> functions accept Unicode strings containing only ASCII characters. Other functions only accept <a class="reference internal" href="../glossary#term-bytes-like-object"><span class="xref std std-term">bytes-like objects</span></a> (such as <a class="reference internal" href="stdtypes#bytes" title="bytes"><code>bytes</code></a>, <a class="reference internal" href="stdtypes#bytearray" title="bytearray"><code>bytearray</code></a> and other objects that support the buffer protocol).</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.3: </span>ASCII-only unicode strings are now accepted by the <code>a2b_*</code> functions.</p> </div> </div> <p>The <a class="reference internal" href="#module-binascii" title="binascii: Tools for converting between binary and various ASCII-encoded binary representations."><code>binascii</code></a> module defines the following functions:</p> <dl class="py function"> <dt class="sig sig-object py" id="binascii.a2b_uu">
+<code>binascii.a2b_uu(string)</code> </dt> <dd>
+<p>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.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="binascii.b2a_uu">
+<code>binascii.b2a_uu(data, *, backtick=False)</code> </dt> <dd>
+<p>Convert binary data to a line of ASCII characters, the return value is the converted line, including a newline char. The length of <em>data</em> should be at most 45. If <em>backtick</em> is true, zeros are represented by <code>'`'</code> instead of spaces.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.7: </span>Added the <em>backtick</em> parameter.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="binascii.a2b_base64">
+<code>binascii.a2b_base64(string, /, *, strict_mode=False)</code> </dt> <dd>
+<p>Convert a block of base64 data back to binary and return the binary data. More than one line may be passed at a time.</p> <p>If <em>strict_mode</em> is true, only valid base64 data will be converted. Invalid base64 data will raise <a class="reference internal" href="#binascii.Error" title="binascii.Error"><code>binascii.Error</code></a>.</p> <p>Valid base64:</p> <ul class="simple"> <li>Conforms to <span class="target" id="index-1"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc3548.html"><strong>RFC 3548</strong></a>.</li> <li>Contains only characters from the base64 alphabet.</li> <li>Contains no excess data after padding (including excess padding, newlines, etc.).</li> <li>Does not start with a padding.</li> </ul> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.11: </span>Added the <em>strict_mode</em> parameter.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="binascii.b2a_base64">
+<code>binascii.b2a_base64(data, *, newline=True)</code> </dt> <dd>
+<p>Convert binary data to a line of ASCII characters in base64 coding. The return value is the converted line, including a newline char if <em>newline</em> is true. The output of this function conforms to <span class="target" id="index-2"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc3548.html"><strong>RFC 3548</strong></a>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.6: </span>Added the <em>newline</em> parameter.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="binascii.a2b_qp">
+<code>binascii.a2b_qp(data, header=False)</code> </dt> <dd>
+<p>Convert a block of quoted-printable data back to binary and return the binary data. More than one line may be passed at a time. If the optional argument <em>header</em> is present and true, underscores will be decoded as spaces.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="binascii.b2a_qp">
+<code>binascii.b2a_qp(data, quotetabs=False, istext=True, header=False)</code> </dt> <dd>
+<p>Convert binary data to a line(s) of ASCII characters in quoted-printable encoding. The return value is the converted line(s). If the optional argument <em>quotetabs</em> is present and true, all tabs and spaces will be encoded. If the optional argument <em>istext</em> is present and true, newlines are not encoded but trailing whitespace will be encoded. If the optional argument <em>header</em> is present and true, spaces will be encoded as underscores per <span class="target" id="index-3"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1522.html"><strong>RFC 1522</strong></a>. If the optional argument <em>header</em> is present and false, newline characters will be encoded as well; otherwise linefeed conversion might corrupt the binary data stream.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="binascii.crc_hqx">
+<code>binascii.crc_hqx(data, value)</code> </dt> <dd>
+<p>Compute a 16-bit CRC value of <em>data</em>, starting with <em>value</em> as the initial CRC, and return the result. This uses the CRC-CCITT polynomial <em>x</em><sup>16</sup> + <em>x</em><sup>12</sup> + <em>x</em><sup>5</sup> + 1, often represented as 0x1021. This CRC is used in the binhex4 format.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="binascii.crc32">
+<code>binascii.crc32(data[, value])</code> </dt> <dd>
+<p>Compute CRC-32, the unsigned 32-bit checksum of <em>data</em>, starting with an initial CRC of <em>value</em>. The default initial CRC is zero. The algorithm is consistent with the ZIP file checksum. Since the algorithm is designed for use as a checksum algorithm, it is not suitable for use as a general hash algorithm. Use as follows:</p> <pre data-language="python">print(binascii.crc32(b"hello world"))
+# Or, in two pieces:
+crc = binascii.crc32(b"hello")
+crc = binascii.crc32(b" world", crc)
+print('crc32 = {:#010x}'.format(crc))
+</pre> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.0: </span>The result is always unsigned.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="binascii.b2a_hex">
+<code>binascii.b2a_hex(data[, sep[, bytes_per_sep=1]])</code> </dt> <dt class="sig sig-object py" id="binascii.hexlify">
+<code>binascii.hexlify(data[, sep[, bytes_per_sep=1]])</code> </dt> <dd>
+<p>Return the hexadecimal representation of the binary <em>data</em>. Every byte of <em>data</em> is converted into the corresponding 2-digit hex representation. The returned bytes object is therefore twice as long as the length of <em>data</em>.</p> <p>Similar functionality (but returning a text string) is also conveniently accessible using the <a class="reference internal" href="stdtypes#bytes.hex" title="bytes.hex"><code>bytes.hex()</code></a> method.</p> <p>If <em>sep</em> is specified, it must be a single character str or bytes object. It will be inserted in the output after every <em>bytes_per_sep</em> input bytes. Separator placement is counted from the right end of the output by default, if you wish to count from the left, supply a negative <em>bytes_per_sep</em> value.</p> <pre data-language="python">&gt;&gt;&gt; import binascii
+&gt;&gt;&gt; binascii.b2a_hex(b'\xb9\x01\xef')
+b'b901ef'
+&gt;&gt;&gt; binascii.hexlify(b'\xb9\x01\xef', '-')
+b'b9-01-ef'
+&gt;&gt;&gt; binascii.b2a_hex(b'\xb9\x01\xef', b'_', 2)
+b'b9_01ef'
+&gt;&gt;&gt; binascii.b2a_hex(b'\xb9\x01\xef', b' ', -2)
+b'b901 ef'
+</pre> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.8: </span>The <em>sep</em> and <em>bytes_per_sep</em> parameters were added.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="binascii.a2b_hex">
+<code>binascii.a2b_hex(hexstr)</code> </dt> <dt class="sig sig-object py" id="binascii.unhexlify">
+<code>binascii.unhexlify(hexstr)</code> </dt> <dd>
+<p>Return the binary data represented by the hexadecimal string <em>hexstr</em>. This function is the inverse of <a class="reference internal" href="#binascii.b2a_hex" title="binascii.b2a_hex"><code>b2a_hex()</code></a>. <em>hexstr</em> must contain an even number of hexadecimal digits (which can be upper or lower case), otherwise an <a class="reference internal" href="#binascii.Error" title="binascii.Error"><code>Error</code></a> exception is raised.</p> <p>Similar functionality (accepting only text string arguments, but more liberal towards whitespace) is also accessible using the <a class="reference internal" href="stdtypes#bytes.fromhex" title="bytes.fromhex"><code>bytes.fromhex()</code></a> class method.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="binascii.Error">
+<code>exception binascii.Error</code> </dt> <dd>
+<p>Exception raised on errors. These are usually programming errors.</p> </dd>
+</dl> <dl class="py exception"> <dt class="sig sig-object py" id="binascii.Incomplete">
+<code>exception binascii.Incomplete</code> </dt> <dd>
+<p>Exception raised on incomplete data. These are usually not programming errors, but may be handled by reading a little more data and trying again.</p> </dd>
+</dl> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt>
+<code>Module</code> <a class="reference internal" href="base64#module-base64" title="base64: RFC 4648: Base16, Base32, Base64 Data Encodings; Base85 and Ascii85"><code>base64</code></a>
+</dt>
+<dd>
+<p>Support for RFC compliant base64-style encoding in base 16, 32, 64, and 85.</p> </dd> <dt>
+<code>Module</code> <a class="reference internal" href="uu#module-uu" title="uu: Encode and decode files in uuencode format. (deprecated)"><code>uu</code></a>
+</dt>
+<dd>
+<p>Support for UU encoding used on Unix.</p> </dd> <dt>
+<code>Module</code> <a class="reference internal" href="quopri#module-quopri" title="quopri: Encode and decode files using the MIME quoted-printable encoding."><code>quopri</code></a>
+</dt>
+<dd>
+<p>Support for quoted-printable encoding used in MIME email messages.</p> </dd> </dl> </div> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
+ <a href="https://docs.python.org/3.12/library/binascii.html" class="_attribution-link">https://docs.python.org/3.12/library/binascii.html</a>
+ </p>
+</div>