merge from 3.4

issue15588 - Correct the quopri module documentation. Mention the correct types
of the parameters on encodestring and decodestring.

Patch by Petri Lehtinen.
This commit is contained in:
Senthil Kumaran 2014-06-25 01:13:19 -07:00
commit b057970f0d
2 changed files with 22 additions and 24 deletions

View File

@ -24,9 +24,8 @@ sending a graphics file.
.. function:: decode(input, output, header=False) .. function:: decode(input, output, header=False)
Decode the contents of the *input* file and write the resulting decoded binary Decode the contents of the *input* file and write the resulting decoded binary
data to the *output* file. *input* and *output* must be :term:`file objects data to the *output* file. *input* and *output* must be :term:`binary file objects
<file object>`. *input* will be read until ``input.readline()`` returns an <file object>`. If the optional argument *header* is present and true, underscore
empty string. If the optional argument *header* is present and true, underscore
will be decoded as space. This is used to decode "Q"-encoded headers as will be decoded as space. This is used to decode "Q"-encoded headers as
described in :rfc:`1522`: "MIME (Multipurpose Internet Mail Extensions) described in :rfc:`1522`: "MIME (Multipurpose Internet Mail Extensions)
Part Two: Message Header Extensions for Non-ASCII Text". Part Two: Message Header Extensions for Non-ASCII Text".
@ -34,27 +33,28 @@ sending a graphics file.
.. function:: encode(input, output, quotetabs, header=False) .. function:: encode(input, output, quotetabs, header=False)
Encode the contents of the *input* file and write the resulting quoted-printable Encode the contents of the *input* file and write the resulting quoted-
data to the *output* file. *input* and *output* must be :term:`file objects printable data to the *output* file. *input* and *output* must be
<file object>`. *input* will be read until ``input.readline()`` returns an :term:`binary file objects <file object>`. *quotetabs*, a flag which controls
empty string. *quotetabs* is a flag which controls whether to encode embedded whether to encode embedded spaces and tabs must be provideda and when true it
spaces and tabs; when true it encodes such embedded whitespace, and when encodes such embedded whitespace, and when false it leaves them unencoded.
false it leaves them unencoded. Note that spaces and tabs appearing at the Note that spaces and tabs appearing at the end of lines are always encoded,
end of lines are always encoded, as per :rfc:`1521`. *header* is a flag as per :rfc:`1521`. *header* is a flag which controls if spaces are encoded
which controls if spaces are encoded as underscores as per :rfc:`1522`. as underscores as per :rfc:`1522`.
.. function:: decodestring(s, header=False) .. function:: decodestring(s, header=False)
Like :func:`decode`, except that it accepts a source string and returns the Like :func:`decode`, except that it accepts a source :class:`bytes` and
corresponding decoded string. returns the corresponding decoded :class:`bytes`.
.. function:: encodestring(s, quotetabs=False, header=False) .. function:: encodestring(s, quotetabs=False, header=False)
Like :func:`encode`, except that it accepts a source string and returns the Like :func:`encode`, except that it accepts a source :class:`bytes` and
corresponding encoded string. *quotetabs* and *header* are optional returns the corresponding encoded :class:`bytes`. By default, it sends a
(defaulting to ``False``), and are passed straight through to :func:`encode`. False value to *quotetabs* parameter of the :func:`encode` function.
.. seealso:: .. seealso::

View File

@ -44,13 +44,11 @@ def quote(c):
def encode(input, output, quotetabs, header=False): def encode(input, output, quotetabs, header=False):
"""Read 'input', apply quoted-printable encoding, and write to 'output'. """Read 'input', apply quoted-printable encoding, and write to 'output'.
'input' and 'output' are files with readline() and write() methods. 'input' and 'output' are binary file objects. The 'quotetabs' flag
The 'quotetabs' flag indicates whether embedded tabs and spaces should be indicates whether embedded tabs and spaces should be quoted. Note that
quoted. Note that line-ending tabs and spaces are always encoded, as per line-ending tabs and spaces are always encoded, as per RFC 1521.
RFC 1521. The 'header' flag indicates whether we are encoding spaces as _ as per RFC
The 'header' flag indicates whether we are encoding spaces as _ as per 1522."""
RFC 1522.
"""
if b2a_qp is not None: if b2a_qp is not None:
data = input.read() data = input.read()
@ -118,7 +116,7 @@ def encodestring(s, quotetabs=False, header=False):
def decode(input, output, header=False): def decode(input, output, header=False):
"""Read 'input', apply quoted-printable decoding, and write to 'output'. """Read 'input', apply quoted-printable decoding, and write to 'output'.
'input' and 'output' are files with readline() and write() methods. 'input' and 'output' are binary file objects.
If 'header' is true, decode underscore as space (per RFC 1522).""" If 'header' is true, decode underscore as space (per RFC 1522)."""
if a2b_qp is not None: if a2b_qp is not None: