blob: 75e1498a7ba749f7d2b6a3cab3d8d1b5ef95f442 [file] [log] [blame]
Fred Drake1aabe5e1998-02-19 18:29:18 +00001\section{Built-in Module \sectcode{binascii}}
2\label{module-binascii}
Jack Jansen4549b131995-08-29 11:30:24 +00003\bimodindex{binascii}
4
5The binascii module contains a number of methods to convert between
6binary and various ascii-encoded binary representations. Normally, you
7will not use these modules directly but use wrapper modules like
8\var{uu} or \var{hexbin} in stead, this module solely exists because
9bit-manipuation of large amounts of data is slow in python.
10
11The \code{binascii} module defines the following functions:
12
Fred Drake19479911998-02-13 06:58:54 +000013\setindexsubitem{(in module binascii)}
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}
22Convert binary data to a line of ascii characters, the return value is
23the converted line, including a newline char. The length of \var{data}
24should be at most 45.
25\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}
33Convert binary data to a line of ascii characters in base64 coding.
34The 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}
40Convert binhex4 formatted ascii data to binary, without doing
41rle-decompression. The string should contain a complete number of
42binary 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
52case the \var{Incomplete} exception is raised.
53\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}
61Perform hexbin4 binary-to-ascii translation and return the resulting
62string. The argument should already be rle-coded, and have a length
63divisible by 3 (except possibly the last fragment).
64\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
77errors, but handled by reading a little more data and trying again.
78\end{excdesc}