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