blob: dca25d012142df4c2e35e6e7cce46aa970e9c825 [file] [log] [blame]
Fred Drake674e0fd1998-04-02 16:24:29 +00001\section{Standard Module \module{base64}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-base64}
Guido van Rossume76b7a81997-04-27 21:25:52 +00003\stmodindex{base64}
Fred Drake674e0fd1998-04-02 16:24:29 +00004\indexii{base64}{encoding}
5\index{MIME!base64 encoding}
Guido van Rossume76b7a81997-04-27 21:25:52 +00006
Fred Drake674e0fd1998-04-02 16:24:29 +00007This module perform base64 encoding and decoding of arbitrary binary
Guido van Rossume76b7a81997-04-27 21:25:52 +00008strings into text strings that can be safely emailed or posted. The
Fred Drake674e0fd1998-04-02 16:24:29 +00009encoding scheme is defined in \rfc{1421} (``Privacy Enhancement for
10Internet Electronic Mail: Part I: Message Encryption and
11Authentication Procedures'', section 4.3.2.4, ``Step 4: Printable
12Encoding'') and is used for MIME email and
Guido van Rossume76b7a81997-04-27 21:25:52 +000013various other Internet-related applications; it is not the same as the
Fred Drake674e0fd1998-04-02 16:24:29 +000014output produced by the \program{uuencode} program. For example, the
Guido van Rossume76b7a81997-04-27 21:25:52 +000015string \code{'www.python.org'} is encoded as the string
16\code{'d3d3LnB5dGhvbi5vcmc=\e n'}.
Guido van Rossume76b7a81997-04-27 21:25:52 +000017
Fred Drake798654f1997-11-30 05:53:22 +000018
Fred Drake79948431998-01-07 03:47:10 +000019\begin{funcdesc}{decode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000020Decode the contents of the \var{input} file and write the resulting
21binary data to the \var{output} file.
22\var{input} and \var{output} must either be file objects or objects that
23mimic the file object interface. \var{input} will be read until
24\code{\var{input}.read()} returns an empty string.
25\end{funcdesc}
26
27\begin{funcdesc}{decodestring}{s}
28Decode the string \var{s}, which must contain one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000029base64 encoded data, and return a string containing the resulting
Guido van Rossume76b7a81997-04-27 21:25:52 +000030binary data.
31\end{funcdesc}
32
Fred Drake79948431998-01-07 03:47:10 +000033\begin{funcdesc}{encode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000034Encode the contents of the \var{input} file and write the resulting
Fred Drake674e0fd1998-04-02 16:24:29 +000035base64 encoded data to the \var{output} file.
Guido van Rossume76b7a81997-04-27 21:25:52 +000036\var{input} and \var{output} must either be file objects or objects that
37mimic the file object interface. \var{input} will be read until
38\code{\var{input}.read()} returns an empty string.
39\end{funcdesc}
40
41\begin{funcdesc}{encodestring}{s}
42Encode the string \var{s}, which can contain arbitrary binary data,
43and return a string containing one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000044base64 encoded data.
Guido van Rossume76b7a81997-04-27 21:25:52 +000045\end{funcdesc}