Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{base64} --- |
Fred Drake | 180b68b | 1999-02-22 13:45:09 +0000 | [diff] [blame] | 2 | Encode and decode MIME base64 data} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | |
Fred Drake | 180b68b | 1999-02-22 13:45:09 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{base64} |
| 5 | \modulesynopsis{Encode and decode files using the MIME base64 data.} |
| 6 | |
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 | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 13 | encoding scheme is defined in \rfc{1521} (\emph{MIME |
| 14 | (Multipurpose Internet Mail Extensions) Part One: Mechanisms for |
| 15 | Specifying and Describing the Format of Internet Message Bodies}, |
| 16 | section 5.2, ``Base64 Content-Transfer-Encoding'') and is used for |
| 17 | MIME email and various other Internet-related applications; it is not |
| 18 | the same as the output produced by the \program{uuencode} program. |
| 19 | For example, the string \code{'www.python.org'} is encoded as the |
| 20 | string \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} |
Fred Drake | ae35aa8 | 1999-04-23 15:52:18 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | \begin{seealso} |
Fred Drake | ba0a989 | 2000-10-18 17:43:06 +0000 | [diff] [blame] | 53 | \seemodule{binascii}{Support module containing \ASCII{}-to-binary |
| 54 | and binary-to-\ASCII{} conversions.} |
Fred Drake | e20bd19 | 2001-04-12 16:47:17 +0000 | [diff] [blame] | 55 | \seerfc{1521}{MIME (Multipurpose Internet Mail Extensions) Part One: |
| 56 | Mechanisms for Specifying and Describing the Format of |
| 57 | Internet Message Bodies}{Section 5.2, ``Base64 |
| 58 | Content-Transfer-Encoding,'' provides the definition of the |
| 59 | base64 encoding.} |
Fred Drake | ae35aa8 | 1999-04-23 15:52:18 +0000 | [diff] [blame] | 60 | \end{seealso} |