Fred Drake | 930f134 | 1998-04-03 03:44:56 +0000 | [diff] [blame] | 1 | \section{Built-in Module \module{binascii}} |
Fred Drake | 1aabe5e | 1998-02-19 18:29:18 +0000 | [diff] [blame] | 2 | \label{module-binascii} |
Jack Jansen | 4549b13 | 1995-08-29 11:30:24 +0000 | [diff] [blame] | 3 | \bimodindex{binascii} |
| 4 | |
Fred Drake | 930f134 | 1998-04-03 03:44:56 +0000 | [diff] [blame] | 5 | The \module{binascii} module contains a number of methods to convert |
| 6 | between binary and various \ASCII{}-encoded binary |
| 7 | representations. Normally, you will not use these modules directly but |
| 8 | use wrapper modules like \module{uu}\refstmodindex{uu} or |
| 9 | \module{hexbin}\refstmodindex{hexbin} instead, this module solely |
| 10 | exists because bit-manipuation of large amounts of data is slow in |
| 11 | Python. |
Jack Jansen | 4549b13 | 1995-08-29 11:30:24 +0000 | [diff] [blame] | 12 | |
Fred Drake | 930f134 | 1998-04-03 03:44:56 +0000 | [diff] [blame] | 13 | The \module{binascii} module defines the following functions: |
Jack Jansen | 4549b13 | 1995-08-29 11:30:24 +0000 | [diff] [blame] | 14 | |
| 15 | \begin{funcdesc}{a2b_uu}{string} |
| 16 | Convert a single line of uuencoded data back to binary and return the |
| 17 | binary data. Lines normally contain 45 (binary) bytes, except for the |
| 18 | last line. Line data may be followed by whitespace. |
| 19 | \end{funcdesc} |
| 20 | |
| 21 | \begin{funcdesc}{b2a_uu}{data} |
Fred Drake | 930f134 | 1998-04-03 03:44:56 +0000 | [diff] [blame] | 22 | Convert binary data to a line of \ASCII{} characters, the return value |
| 23 | is the converted line, including a newline char. The length of |
| 24 | \var{data} should be at most 45. |
Jack Jansen | 4549b13 | 1995-08-29 11:30:24 +0000 | [diff] [blame] | 25 | \end{funcdesc} |
| 26 | |
Jack Jansen | 06cf5d0 | 1995-10-10 14:41:03 +0000 | [diff] [blame] | 27 | \begin{funcdesc}{a2b_base64}{string} |
| 28 | Convert a block of base64 data back to binary and return the |
| 29 | binary data. More than one line may be passed at a time. |
| 30 | \end{funcdesc} |
| 31 | |
| 32 | \begin{funcdesc}{b2a_base64}{data} |
Fred Drake | 930f134 | 1998-04-03 03:44:56 +0000 | [diff] [blame] | 33 | Convert binary data to a line of \ASCII{} characters in base64 coding. |
Jack Jansen | 06cf5d0 | 1995-10-10 14:41:03 +0000 | [diff] [blame] | 34 | The return value is the converted line, including a newline char. |
| 35 | The length of \var{data} should be at most 57 to adhere to the base64 |
| 36 | standard. |
| 37 | \end{funcdesc} |
| 38 | |
Jack Jansen | 4549b13 | 1995-08-29 11:30:24 +0000 | [diff] [blame] | 39 | \begin{funcdesc}{a2b_hqx}{string} |
Fred Drake | 930f134 | 1998-04-03 03:44:56 +0000 | [diff] [blame] | 40 | Convert binhex4 formatted \ASCII{} data to binary, without doing |
| 41 | RLE-decompression. The string should contain a complete number of |
Jack Jansen | 4549b13 | 1995-08-29 11:30:24 +0000 | [diff] [blame] | 42 | binary bytes, or (in case of the last portion of the binhex4 data) |
| 43 | have the remaining bits zero. |
| 44 | \end{funcdesc} |
| 45 | |
| 46 | \begin{funcdesc}{rledecode_hqx}{data} |
| 47 | Perform RLE-decompression on the data, as per the binhex4 |
| 48 | standard. The algorithm uses \code{0x90} after a byte as a repeat |
| 49 | indicator, followed by a count. A count of \code{0} specifies a byte |
| 50 | value of \code{0x90}. The routine returns the decompressed data, |
| 51 | unless data input data ends in an orphaned repeat indicator, in which |
Fred Drake | 930f134 | 1998-04-03 03:44:56 +0000 | [diff] [blame] | 52 | case the \exception{Incomplete} exception is raised. |
Jack Jansen | 4549b13 | 1995-08-29 11:30:24 +0000 | [diff] [blame] | 53 | \end{funcdesc} |
| 54 | |
| 55 | \begin{funcdesc}{rlecode_hqx}{data} |
| 56 | Perform binhex4 style RLE-compression on \var{data} and return the |
| 57 | result. |
| 58 | \end{funcdesc} |
| 59 | |
| 60 | \begin{funcdesc}{b2a_hqx}{data} |
Fred Drake | 930f134 | 1998-04-03 03:44:56 +0000 | [diff] [blame] | 61 | Perform hexbin4 binary-to-\ASCII{} translation and return the |
| 62 | resulting string. The argument should already be RLE-coded, and have a |
| 63 | length divisible by 3 (except possibly the last fragment). |
Jack Jansen | 4549b13 | 1995-08-29 11:30:24 +0000 | [diff] [blame] | 64 | \end{funcdesc} |
| 65 | |
| 66 | \begin{funcdesc}{crc_hqx}{data, crc} |
| 67 | Compute 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} |
| 72 | Exception raised on errors. These are usually programming errors. |
| 73 | \end{excdesc} |
| 74 | |
| 75 | \begin{excdesc}{Incomplete} |
| 76 | Exception raised on incomplete data. These are usually not programming |
Fred Drake | 930f134 | 1998-04-03 03:44:56 +0000 | [diff] [blame] | 77 | errors, but may be handled by reading a little more data and trying |
| 78 | again. |
Jack Jansen | 4549b13 | 1995-08-29 11:30:24 +0000 | [diff] [blame] | 79 | \end{excdesc} |