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