blob: 24525d1d3cbb35f841b54a38c7761f98578167fb [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{base64} ---
Fred Drake180b68b1999-02-22 13:45:09 +00002 Encode and decode MIME base64 data}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drake180b68b1999-02-22 13:45:09 +00004\declaremodule{standard}{base64}
5\modulesynopsis{Encode and decode files using the MIME base64 data.}
6
Fred Drakeb91e9341998-07-23 17:59:49 +00007
Fred Drake674e0fd1998-04-02 16:24:29 +00008\indexii{base64}{encoding}
9\index{MIME!base64 encoding}
Guido van Rossume76b7a81997-04-27 21:25:52 +000010
Fred Drake6a50ba81998-05-22 18:19:19 +000011This module performs base64 encoding and decoding of arbitrary binary
Guido van Rossume76b7a81997-04-27 21:25:52 +000012strings into text strings that can be safely emailed or posted. The
Fred Drake38e5d272000-04-03 20:13:55 +000013encoding scheme is defined in \rfc{1521} (\emph{MIME
14(Multipurpose Internet Mail Extensions) Part One: Mechanisms for
15Specifying and Describing the Format of Internet Message Bodies},
16section 5.2, ``Base64 Content-Transfer-Encoding'') and is used for
17MIME email and various other Internet-related applications; it is not
18the same as the output produced by the \program{uuencode} program.
19For example, the string \code{'www.python.org'} is encoded as the
20string \code{'d3d3LnB5dGhvbi5vcmc=\e n'}.
Guido van Rossume76b7a81997-04-27 21:25:52 +000021
Fred Drake798654f1997-11-30 05:53:22 +000022
Fred Drake79948431998-01-07 03:47:10 +000023\begin{funcdesc}{decode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000024Decode the contents of the \var{input} file and write the resulting
25binary data to the \var{output} file.
26\var{input} and \var{output} must either be file objects or objects that
27mimic 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}
32Decode the string \var{s}, which must contain one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000033base64 encoded data, and return a string containing the resulting
Guido van Rossume76b7a81997-04-27 21:25:52 +000034binary data.
35\end{funcdesc}
36
Fred Drake79948431998-01-07 03:47:10 +000037\begin{funcdesc}{encode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000038Encode the contents of the \var{input} file and write the resulting
Fred Drake674e0fd1998-04-02 16:24:29 +000039base64 encoded data to the \var{output} file.
Guido van Rossume76b7a81997-04-27 21:25:52 +000040\var{input} and \var{output} must either be file objects or objects that
41mimic 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}
46Encode the string \var{s}, which can contain arbitrary binary data,
47and return a string containing one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000048base64 encoded data.
Guido van Rossume76b7a81997-04-27 21:25:52 +000049\end{funcdesc}
Fred Drakeae35aa81999-04-23 15:52:18 +000050
51
52\begin{seealso}
Fred Drakeba0a9892000-10-18 17:43:06 +000053 \seemodule{binascii}{Support module containing \ASCII{}-to-binary
54 and binary-to-\ASCII{} conversions.}
Fred Drakee20bd192001-04-12 16:47:17 +000055 \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 Drakeae35aa81999-04-23 15:52:18 +000060\end{seealso}