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