Fred Drake | 674e0fd | 1998-04-02 16:24:29 +0000 | [diff] [blame] | 1 | \section{Standard Module \module{base64}} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 2 | \declaremodule{standard}{base64} |
| 3 | |
| 4 | \modulesynopsis{Encode/decode binary files using the MIME base64 encoding.} |
| 5 | |
Fred Drake | 674e0fd | 1998-04-02 16:24:29 +0000 | [diff] [blame] | 6 | \indexii{base64}{encoding} |
| 7 | \index{MIME!base64 encoding} |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 8 | |
Fred Drake | 6a50ba8 | 1998-05-22 18:19:19 +0000 | [diff] [blame] | 9 | This module performs base64 encoding and decoding of arbitrary binary |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 10 | strings into text strings that can be safely emailed or posted. The |
Fred Drake | 674e0fd | 1998-04-02 16:24:29 +0000 | [diff] [blame] | 11 | encoding scheme is defined in \rfc{1421} (``Privacy Enhancement for |
| 12 | Internet Electronic Mail: Part I: Message Encryption and |
| 13 | Authentication Procedures'', section 4.3.2.4, ``Step 4: Printable |
| 14 | Encoding'') and is used for MIME email and |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 15 | various other Internet-related applications; it is not the same as the |
Fred Drake | 674e0fd | 1998-04-02 16:24:29 +0000 | [diff] [blame] | 16 | output produced by the \program{uuencode} program. For example, the |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 17 | string \code{'www.python.org'} is encoded as the string |
| 18 | \code{'d3d3LnB5dGhvbi5vcmc=\e n'}. |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 19 | |
Fred Drake | 798654f | 1997-11-30 05:53:22 +0000 | [diff] [blame] | 20 | |
Fred Drake | 7994843 | 1998-01-07 03:47:10 +0000 | [diff] [blame] | 21 | \begin{funcdesc}{decode}{input, output} |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 22 | Decode the contents of the \var{input} file and write the resulting |
| 23 | binary data to the \var{output} file. |
| 24 | \var{input} and \var{output} must either be file objects or objects that |
| 25 | mimic the file object interface. \var{input} will be read until |
| 26 | \code{\var{input}.read()} returns an empty string. |
| 27 | \end{funcdesc} |
| 28 | |
| 29 | \begin{funcdesc}{decodestring}{s} |
| 30 | Decode the string \var{s}, which must contain one or more lines of |
Fred Drake | 674e0fd | 1998-04-02 16:24:29 +0000 | [diff] [blame] | 31 | base64 encoded data, and return a string containing the resulting |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 32 | binary data. |
| 33 | \end{funcdesc} |
| 34 | |
Fred Drake | 7994843 | 1998-01-07 03:47:10 +0000 | [diff] [blame] | 35 | \begin{funcdesc}{encode}{input, output} |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 36 | Encode the contents of the \var{input} file and write the resulting |
Fred Drake | 674e0fd | 1998-04-02 16:24:29 +0000 | [diff] [blame] | 37 | base64 encoded data to the \var{output} file. |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 38 | \var{input} and \var{output} must either be file objects or objects that |
| 39 | mimic the file object interface. \var{input} will be read until |
| 40 | \code{\var{input}.read()} returns an empty string. |
| 41 | \end{funcdesc} |
| 42 | |
| 43 | \begin{funcdesc}{encodestring}{s} |
| 44 | Encode the string \var{s}, which can contain arbitrary binary data, |
| 45 | and return a string containing one or more lines of |
Fred Drake | 674e0fd | 1998-04-02 16:24:29 +0000 | [diff] [blame] | 46 | base64 encoded data. |
Guido van Rossum | e76b7a8 | 1997-04-27 21:25:52 +0000 | [diff] [blame] | 47 | \end{funcdesc} |