blob: 8f525efdf82dfce98a7483267b4c0cc46251e873 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2:mod:`quopri` --- Encode and decode MIME quoted-printable data
3==============================================================
4
5.. module:: quopri
6 :synopsis: Encode and decode files using the MIME quoted-printable encoding.
7
8
9.. index::
10 pair: quoted-printable; encoding
11 single: MIME; quoted-printable encoding
12
13This module performs quoted-printable transport encoding and decoding, as
14defined in :rfc:`1521`: "MIME (Multipurpose Internet Mail Extensions) Part One:
15Mechanisms for Specifying and Describing the Format of Internet Message Bodies".
16The quoted-printable encoding is designed for data where there are relatively
17few nonprintable characters; the base64 encoding scheme available via the
18:mod:`base64` module is more compact if there are many such characters, as when
19sending a graphics file.
20
21
22.. function:: decode(input, output[,header])
23
24 Decode the contents of the *input* file and write the resulting decoded binary
25 data to the *output* file. *input* and *output* must either be file objects or
26 objects that mimic the file object interface. *input* will be read until
27 ``input.readline()`` returns an empty string. If the optional argument *header*
28 is present and true, underscore will be decoded as space. This is used to decode
29 "Q"-encoded headers as described in :rfc:`1522`: "MIME (Multipurpose Internet
30 Mail Extensions) Part Two: Message Header Extensions for Non-ASCII Text".
31
32
33.. function:: encode(input, output, quotetabs)
34
35 Encode the contents of the *input* file and write the resulting quoted-printable
36 data to the *output* file. *input* and *output* must either be file objects or
37 objects that mimic the file object interface. *input* will be read until
38 ``input.readline()`` returns an empty string. *quotetabs* is a flag which
39 controls whether to encode embedded spaces and tabs; when true it encodes such
40 embedded whitespace, and when false it leaves them unencoded. Note that spaces
41 and tabs appearing at the end of lines are always encoded, as per :rfc:`1521`.
42
43
44.. function:: decodestring(s[,header])
45
46 Like :func:`decode`, except that it accepts a source string and returns the
47 corresponding decoded string.
48
49
50.. function:: encodestring(s[, quotetabs])
51
52 Like :func:`encode`, except that it accepts a source string and returns the
53 corresponding encoded string. *quotetabs* is optional (defaulting to 0), and is
54 passed straight through to :func:`encode`.
55
56
57.. seealso::
58
59 Module :mod:`base64`
60 Encode and decode MIME base64 data
61