blob: aedb6963928e840a8970ad31a0f3b4c9872975a0 [file] [log] [blame]
Fred Drake930f1341998-04-03 03:44:56 +00001\section{Built-in Module \module{binascii}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{builtin}{binascii}
3
Fred Drake2d623951998-08-07 16:00:30 +00004\modulesynopsis{Tools for converting between binary and various
5ascii-encoded binary representations.}
Fred Drakeb91e9341998-07-23 17:59:49 +00006
Jack Jansen4549b131995-08-29 11:30:24 +00007
Fred Drake930f1341998-04-03 03:44:56 +00008The \module{binascii} module contains a number of methods to convert
9between binary and various \ASCII{}-encoded binary
10representations. Normally, you will not use these modules directly but
11use wrapper modules like \module{uu}\refstmodindex{uu} or
12\module{hexbin}\refstmodindex{hexbin} instead, this module solely
13exists because bit-manipuation of large amounts of data is slow in
14Python.
Jack Jansen4549b131995-08-29 11:30:24 +000015
Fred Drake930f1341998-04-03 03:44:56 +000016The \module{binascii} module defines the following functions:
Jack Jansen4549b131995-08-29 11:30:24 +000017
18\begin{funcdesc}{a2b_uu}{string}
19Convert a single line of uuencoded data back to binary and return the
20binary data. Lines normally contain 45 (binary) bytes, except for the
21last line. Line data may be followed by whitespace.
22\end{funcdesc}
23
24\begin{funcdesc}{b2a_uu}{data}
Fred Drake930f1341998-04-03 03:44:56 +000025Convert binary data to a line of \ASCII{} characters, the return value
26is the converted line, including a newline char. The length of
27\var{data} should be at most 45.
Jack Jansen4549b131995-08-29 11:30:24 +000028\end{funcdesc}
29
Jack Jansen06cf5d01995-10-10 14:41:03 +000030\begin{funcdesc}{a2b_base64}{string}
31Convert a block of base64 data back to binary and return the
32binary data. More than one line may be passed at a time.
33\end{funcdesc}
34
35\begin{funcdesc}{b2a_base64}{data}
Fred Drake930f1341998-04-03 03:44:56 +000036Convert binary data to a line of \ASCII{} characters in base64 coding.
Jack Jansen06cf5d01995-10-10 14:41:03 +000037The return value is the converted line, including a newline char.
38The length of \var{data} should be at most 57 to adhere to the base64
39standard.
40\end{funcdesc}
41
Jack Jansen4549b131995-08-29 11:30:24 +000042\begin{funcdesc}{a2b_hqx}{string}
Fred Drake930f1341998-04-03 03:44:56 +000043Convert binhex4 formatted \ASCII{} data to binary, without doing
44RLE-decompression. The string should contain a complete number of
Jack Jansen4549b131995-08-29 11:30:24 +000045binary bytes, or (in case of the last portion of the binhex4 data)
46have the remaining bits zero.
47\end{funcdesc}
48
49\begin{funcdesc}{rledecode_hqx}{data}
50Perform RLE-decompression on the data, as per the binhex4
51standard. The algorithm uses \code{0x90} after a byte as a repeat
52indicator, followed by a count. A count of \code{0} specifies a byte
53value of \code{0x90}. The routine returns the decompressed data,
54unless data input data ends in an orphaned repeat indicator, in which
Fred Drake930f1341998-04-03 03:44:56 +000055case the \exception{Incomplete} exception is raised.
Jack Jansen4549b131995-08-29 11:30:24 +000056\end{funcdesc}
57
58\begin{funcdesc}{rlecode_hqx}{data}
59Perform binhex4 style RLE-compression on \var{data} and return the
60result.
61\end{funcdesc}
62
63\begin{funcdesc}{b2a_hqx}{data}
Fred Drake930f1341998-04-03 03:44:56 +000064Perform hexbin4 binary-to-\ASCII{} translation and return the
65resulting string. The argument should already be RLE-coded, and have a
66length divisible by 3 (except possibly the last fragment).
Jack Jansen4549b131995-08-29 11:30:24 +000067\end{funcdesc}
68
69\begin{funcdesc}{crc_hqx}{data, crc}
70Compute the binhex4 crc value of \var{data}, starting with an initial
71\var{crc} and returning the result.
72\end{funcdesc}
73
74\begin{excdesc}{Error}
75Exception raised on errors. These are usually programming errors.
76\end{excdesc}
77
78\begin{excdesc}{Incomplete}
79Exception raised on incomplete data. These are usually not programming
Fred Drake930f1341998-04-03 03:44:56 +000080errors, but may be handled by reading a little more data and trying
81again.
Jack Jansen4549b131995-08-29 11:30:24 +000082\end{excdesc}