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 | |
Éric Araujo | 6e6cb8e | 2010-11-16 19:13:50 +0000 | [diff] [blame] | 20 | .. seealso:: |
| 21 | |
| 22 | Latest version of the :source:`quopri module Python source code |
| 23 | <Lib/quopri.py>` |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 24 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 25 | .. function:: decode(input, output, header=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 26 | |
| 27 | Decode the contents of the *input* file and write the resulting decoded binary |
Antoine Pitrou | 11cb961 | 2010-09-15 11:11:28 +0000 | [diff] [blame] | 28 | data to the *output* file. *input* and *output* must be :term:`file objects |
| 29 | <file object>`. *input* will be read until ``input.readline()`` returns an |
| 30 | empty string. If the optional argument *header* is present and true, underscore |
| 31 | will be decoded as space. This is used to decode "Q"-encoded headers as |
| 32 | described in :rfc:`1522`: "MIME (Multipurpose Internet Mail Extensions) |
| 33 | Part Two: Message Header Extensions for Non-ASCII Text". |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 34 | |
| 35 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 36 | .. function:: encode(input, output, quotetabs, header=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 37 | |
| 38 | Encode the contents of the *input* file and write the resulting quoted-printable |
Antoine Pitrou | 11cb961 | 2010-09-15 11:11:28 +0000 | [diff] [blame] | 39 | data to the *output* file. *input* and *output* must be :term:`file objects |
| 40 | <file object>`. *input* will be read until ``input.readline()`` returns an |
| 41 | empty string. *quotetabs* is a flag which controls whether to encode embedded |
| 42 | spaces and tabs; when true it encodes such embedded whitespace, and when |
| 43 | false it leaves them unencoded. Note that spaces and tabs appearing at the |
| 44 | end of lines are always encoded, as per :rfc:`1521`. *header* is a flag |
| 45 | which controls if spaces are encoded as underscores as per :rfc:`1522`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 46 | |
| 47 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 48 | .. function:: decodestring(s, header=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 49 | |
| 50 | Like :func:`decode`, except that it accepts a source string and returns the |
| 51 | corresponding decoded string. |
| 52 | |
| 53 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 54 | .. function:: encodestring(s, quotetabs=False, header=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 55 | |
| 56 | 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] | 57 | corresponding encoded string. *quotetabs* and *header* are optional |
| 58 | (defaulting to ``False``), and are passed straight through to :func:`encode`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 59 | |
| 60 | |
| 61 | .. seealso:: |
| 62 | |
| 63 | Module :mod:`base64` |
| 64 | Encode and decode MIME base64 data |
| 65 | |