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 | |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 7 | **Source code:** :source:`Lib/quopri.py` |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 8 | |
| 9 | .. index:: |
| 10 | pair: quoted-printable; encoding |
| 11 | single: MIME; quoted-printable encoding |
| 12 | |
Raymond Hettinger | 05ce079 | 2011-01-10 21:16:07 +0000 | [diff] [blame] | 13 | -------------- |
| 14 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 15 | This module performs quoted-printable transport encoding and decoding, as |
| 16 | defined in :rfc:`1521`: "MIME (Multipurpose Internet Mail Extensions) Part One: |
| 17 | Mechanisms for Specifying and Describing the Format of Internet Message Bodies". |
| 18 | The quoted-printable encoding is designed for data where there are relatively |
| 19 | few nonprintable characters; the base64 encoding scheme available via the |
| 20 | :mod:`base64` module is more compact if there are many such characters, as when |
| 21 | sending a graphics file. |
| 22 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 23 | .. function:: decode(input, output, header=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 24 | |
| 25 | Decode the contents of the *input* file and write the resulting decoded binary |
Senthil Kumaran | 99597c4 | 2014-06-25 01:12:03 -0700 | [diff] [blame] | 26 | data to the *output* file. *input* and *output* must be :term:`binary file objects |
| 27 | <file object>`. If the optional argument *header* is present and true, underscore |
Antoine Pitrou | 11cb961 | 2010-09-15 11:11:28 +0000 | [diff] [blame] | 28 | will be decoded as space. This is used to decode "Q"-encoded headers as |
| 29 | described in :rfc:`1522`: "MIME (Multipurpose Internet Mail Extensions) |
| 30 | Part Two: Message Header Extensions for Non-ASCII Text". |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 31 | |
| 32 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 33 | .. function:: encode(input, output, quotetabs, header=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 34 | |
Martin Panter | 8f13783 | 2017-01-14 08:24:20 +0000 | [diff] [blame] | 35 | Encode the contents of the *input* file and write the resulting quoted-printable |
| 36 | data to the *output* file. *input* and *output* must be |
Julien Palard | 9424dcb | 2018-01-30 04:36:06 +0100 | [diff] [blame] | 37 | :term:`binary file objects <file object>`. *quotetabs*, a |
| 38 | non-optional flag which controls whether to encode embedded spaces |
| 39 | and tabs; when true it encodes such embedded whitespace, and when |
| 40 | false it leaves them unencoded. |
Senthil Kumaran | 99597c4 | 2014-06-25 01:12:03 -0700 | [diff] [blame] | 41 | Note that spaces and tabs appearing at the end of lines are always encoded, |
| 42 | as per :rfc:`1521`. *header* is a flag which controls if spaces are encoded |
| 43 | as underscores as per :rfc:`1522`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 44 | |
| 45 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 46 | .. function:: decodestring(s, header=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 47 | |
Senthil Kumaran | 99597c4 | 2014-06-25 01:12:03 -0700 | [diff] [blame] | 48 | Like :func:`decode`, except that it accepts a source :class:`bytes` and |
| 49 | returns the corresponding decoded :class:`bytes`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 50 | |
| 51 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 52 | .. function:: encodestring(s, quotetabs=False, header=False) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 53 | |
Senthil Kumaran | 99597c4 | 2014-06-25 01:12:03 -0700 | [diff] [blame] | 54 | Like :func:`encode`, except that it accepts a source :class:`bytes` and |
| 55 | returns the corresponding encoded :class:`bytes`. By default, it sends a |
Serhiy Storchaka | 4adf01c | 2016-10-19 18:30:05 +0300 | [diff] [blame] | 56 | ``False`` value to *quotetabs* parameter of the :func:`encode` function. |
Senthil Kumaran | 99597c4 | 2014-06-25 01:12:03 -0700 | [diff] [blame] | 57 | |
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 |