blob: 77366ed8db9c3e12a06afe3949377808dc393358 [file] [log] [blame]
Fred Drake930f1341998-04-03 03:44:56 +00001\section{Built-in Module \module{binascii}}
Fred Drake1aabe5e1998-02-19 18:29:18 +00002\label{module-binascii}
Jack Jansen4549b131995-08-29 11:30:24 +00003\bimodindex{binascii}
4
Fred Drake930f1341998-04-03 03:44:56 +00005The \module{binascii} module contains a number of methods to convert
6between binary and various \ASCII{}-encoded binary
7representations. Normally, you will not use these modules directly but
8use wrapper modules like \module{uu}\refstmodindex{uu} or
9\module{hexbin}\refstmodindex{hexbin} instead, this module solely
10exists because bit-manipuation of large amounts of data is slow in
11Python.
Jack Jansen4549b131995-08-29 11:30:24 +000012
Fred Drake930f1341998-04-03 03:44:56 +000013The \module{binascii} module defines the following functions:
Jack Jansen4549b131995-08-29 11:30:24 +000014
15\begin{funcdesc}{a2b_uu}{string}
16Convert a single line of uuencoded data back to binary and return the
17binary data. Lines normally contain 45 (binary) bytes, except for the
18last line. Line data may be followed by whitespace.
19\end{funcdesc}
20
21\begin{funcdesc}{b2a_uu}{data}
Fred Drake930f1341998-04-03 03:44:56 +000022Convert binary data to a line of \ASCII{} characters, the return value
23is the converted line, including a newline char. The length of
24\var{data} should be at most 45.
Jack Jansen4549b131995-08-29 11:30:24 +000025\end{funcdesc}
26
Jack Jansen06cf5d01995-10-10 14:41:03 +000027\begin{funcdesc}{a2b_base64}{string}
28Convert a block of base64 data back to binary and return the
29binary data. More than one line may be passed at a time.
30\end{funcdesc}
31
32\begin{funcdesc}{b2a_base64}{data}
Fred Drake930f1341998-04-03 03:44:56 +000033Convert binary data to a line of \ASCII{} characters in base64 coding.
Jack Jansen06cf5d01995-10-10 14:41:03 +000034The return value is the converted line, including a newline char.
35The length of \var{data} should be at most 57 to adhere to the base64
36standard.
37\end{funcdesc}
38
Jack Jansen4549b131995-08-29 11:30:24 +000039\begin{funcdesc}{a2b_hqx}{string}
Fred Drake930f1341998-04-03 03:44:56 +000040Convert binhex4 formatted \ASCII{} data to binary, without doing
41RLE-decompression. The string should contain a complete number of
Jack Jansen4549b131995-08-29 11:30:24 +000042binary bytes, or (in case of the last portion of the binhex4 data)
43have the remaining bits zero.
44\end{funcdesc}
45
46\begin{funcdesc}{rledecode_hqx}{data}
47Perform RLE-decompression on the data, as per the binhex4
48standard. The algorithm uses \code{0x90} after a byte as a repeat
49indicator, followed by a count. A count of \code{0} specifies a byte
50value of \code{0x90}. The routine returns the decompressed data,
51unless data input data ends in an orphaned repeat indicator, in which
Fred Drake930f1341998-04-03 03:44:56 +000052case the \exception{Incomplete} exception is raised.
Jack Jansen4549b131995-08-29 11:30:24 +000053\end{funcdesc}
54
55\begin{funcdesc}{rlecode_hqx}{data}
56Perform binhex4 style RLE-compression on \var{data} and return the
57result.
58\end{funcdesc}
59
60\begin{funcdesc}{b2a_hqx}{data}
Fred Drake930f1341998-04-03 03:44:56 +000061Perform hexbin4 binary-to-\ASCII{} translation and return the
62resulting string. The argument should already be RLE-coded, and have a
63length divisible by 3 (except possibly the last fragment).
Jack Jansen4549b131995-08-29 11:30:24 +000064\end{funcdesc}
65
66\begin{funcdesc}{crc_hqx}{data, crc}
67Compute the binhex4 crc value of \var{data}, starting with an initial
68\var{crc} and returning the result.
69\end{funcdesc}
70
71\begin{excdesc}{Error}
72Exception raised on errors. These are usually programming errors.
73\end{excdesc}
74
75\begin{excdesc}{Incomplete}
76Exception raised on incomplete data. These are usually not programming
Fred Drake930f1341998-04-03 03:44:56 +000077errors, but may be handled by reading a little more data and trying
78again.
Jack Jansen4549b131995-08-29 11:30:24 +000079\end{excdesc}