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