blob: 99fb09b224fca0792abced688f1ae72cc5423635 [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 Drake19479911998-02-13 06:58:54 +000018\setindexsubitem{(in module base64)}
Fred Drake798654f1997-11-30 05:53:22 +000019
Fred Drake79948431998-01-07 03:47:10 +000020\begin{funcdesc}{decode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000021Decode the contents of the \var{input} file and write the resulting
22binary data to the \var{output} file.
23\var{input} and \var{output} must either be file objects or objects that
24mimic the file object interface. \var{input} will be read until
25\code{\var{input}.read()} returns an empty string.
26\end{funcdesc}
27
28\begin{funcdesc}{decodestring}{s}
29Decode the string \var{s}, which must contain one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000030base64 encoded data, and return a string containing the resulting
Guido van Rossume76b7a81997-04-27 21:25:52 +000031binary data.
32\end{funcdesc}
33
Fred Drake79948431998-01-07 03:47:10 +000034\begin{funcdesc}{encode}{input, output}
Guido van Rossume76b7a81997-04-27 21:25:52 +000035Encode the contents of the \var{input} file and write the resulting
Fred Drake674e0fd1998-04-02 16:24:29 +000036base64 encoded data to the \var{output} file.
Guido van Rossume76b7a81997-04-27 21:25:52 +000037\var{input} and \var{output} must either be file objects or objects that
38mimic the file object interface. \var{input} will be read until
39\code{\var{input}.read()} returns an empty string.
40\end{funcdesc}
41
42\begin{funcdesc}{encodestring}{s}
43Encode the string \var{s}, which can contain arbitrary binary data,
44and return a string containing one or more lines of
Fred Drake674e0fd1998-04-02 16:24:29 +000045base64 encoded data.
Guido van Rossume76b7a81997-04-27 21:25:52 +000046\end{funcdesc}