Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions Doc/library/email.compat32-message.rst
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,14 @@ Here are the methods of the :class:`Message` class:

.. testsetup::

>>> from email import message_from_binary_file
>>> with open('Lib/test/test_email/data/msg_16.txt', 'rb') as f:
... msg = message_from_binary_file(f)
>>> from email.iterators import _structure
import email
from email import message_from_binary_file
from os.path import join, dirname
lib_dir = dirname(dirname(email.__file__))
file_path = join(lib_dir, 'test/test_email/data/msg_16.txt')
with open(file_path, 'rb') as f:
msg = message_from_binary_file(f)
from email.iterators import _structure

.. doctest::

Expand All @@ -686,7 +690,7 @@ Here are the methods of the :class:`Message` class:
.. doctest::

>>> for part in msg.walk():
... print(part.get_content_maintype() == 'multipart'),
... print(part.get_content_maintype() == 'multipart',
... part.is_multipart())
True True
False False
Expand All @@ -698,11 +702,11 @@ Here are the methods of the :class:`Message` class:
>>> _structure(msg)
multipart/report
text/plain
message/delivery-status
text/plain
text/plain
message/rfc822
text/plain
message/delivery-status
text/plain
text/plain
message/rfc822
text/plain

Here the ``message`` parts are not ``multiparts``, but they do contain
subparts. ``is_multipart()`` returns ``True`` and ``walk`` descends
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ are always available. They are listed here in alphabetical order.
The resulting list is sorted alphabetically. For example:

>>> import struct
>>> dir() # show the names in the module namespace
>>> dir() # show the names in the module namespace # doctest: +SKIP
['__builtins__', '__name__', 'struct']
>>> dir(struct) # show the names in the struct module # doctest: +SKIP
['Struct', '__all__', '__builtins__', '__cached__', '__doc__', '__file__',
Expand Down
8 changes: 5 additions & 3 deletions Doc/library/ipaddress.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ This is the full module API reference—for an overview and introduction, see
.. versionadded:: 3.3

.. testsetup::
>>> import ipaddress
>>> from ipaddress import (ip_network, IPv4Address, IPv4Interface,
... IPv4Network)

import ipaddress
from ipaddress import (
ip_network, IPv4Address, IPv4Interface, IPv4Network,
)

Convenience factory functions
-----------------------------
Expand Down
1 change: 1 addition & 0 deletions Doc/library/reprlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ string instead.
same thread. If a recursive call is made, the *fillvalue* is returned,
otherwise, the usual :meth:`__repr__` call is made. For example:

>>> from reprlib import recursive_repr
>>> class MyList(list):
... @recursive_repr()
... def __repr__(self):
Expand Down
6 changes: 4 additions & 2 deletions Doc/library/shlex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ The :mod:`shlex` module defines the following functions:
string that can safely be used as one token in a shell command line, for
cases where you cannot use a list.

This idiom would be unsafe::
This idiom would be unsafe:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't using "::" be more correct here? I understand the use of "::" is a bit inconsistent in the rest of the file, but I prefer to keep it as is if it doesn't break any doctests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @berkerpeksag , to make the test after The quoting is compatible with UNIX shells to pass, remote_command should be defined. In order for remote_command to be defined, we need to execute this test and the next one, that is why I changed ::`` to ``:. If you want to use :: instead of :, than you have to skip the test that uses the remote_command name, but I do not see any good reason for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment below about skipping tests explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, I think there is a misunderstanding here. I do not want to skip this test group, but I want it to be executed. If we skip these tests then remote_command will not be defined and the next test groups (after The quoting is compatible with UNIX shells) will fail.

Copy link
Contributor Author

@marco-buttu marco-buttu Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @berkerpeksag, only this point is still open. Here I prefere to execute the test, because this example defines remote_command , that is used in a subsequent example. In this way all tests pass. If you want us to skip this test, we have to skip the subsequent tests that use theremote_command name. Let me know which option you prefere. Thank you very much for your time :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forgot to comment on this earlier. Your change looks fine to me. I still need to run the tests locally.


>>> filename = 'somefile; rm -rf ~'
>>> command = 'ls -l {}'.format(filename)
>>> print(command) # executed by a shell: boom!
ls -l somefile; rm -rf ~

:func:`quote` lets you plug the security hole::
:func:`quote` lets you plug the security hole:

>>> from shlex import quote
>>> command = 'ls -l {}'.format(quote(filename))
>>> print(command)
ls -l 'somefile; rm -rf ~'
Expand All @@ -61,6 +62,7 @@ The :mod:`shlex` module defines the following functions:

The quoting is compatible with UNIX shells and with :func:`split`:

>>> from shlex import split
>>> remote_command = split(remote_command)
>>> remote_command
['ssh', 'home', "ls -l 'somefile; rm -rf ~'"]
Expand Down
3 changes: 3 additions & 0 deletions Doc/library/urllib.parse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ or on combining URL components into a URL string.
input is presumed to be a relative URL and thus to start with
a path component.

.. doctest::
:options: +NORMALIZE_WHITESPACE

>>> from urllib.parse import urlparse
>>> urlparse('//www.cwi.nl:80/%7Eguido/Python.html')
ParseResult(scheme='', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html',
Expand Down
19 changes: 11 additions & 8 deletions Doc/whatsnew/3.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1062,13 +1062,16 @@ The :func:`~math.erf` function computes a probability integral or `Gaussian
error function <https://en.wikipedia.org/wiki/Error_function>`_. The
complementary error function, :func:`~math.erfc`, is ``1 - erf(x)``:

>>> from math import erf, erfc, sqrt
>>> erf(1.0/sqrt(2.0)) # portion of normal distribution within 1 standard deviation
0.682689492137086
>>> erfc(1.0/sqrt(2.0)) # portion of normal distribution outside 1 standard deviation
0.31731050786291404
>>> erf(1.0/sqrt(2.0)) + erfc(1.0/sqrt(2.0))
1.0
.. doctest::
:options: +SKIP

>>> from math import erf, erfc, sqrt
>>> erf(1.0/sqrt(2.0)) # portion of normal distribution within 1 standard deviation
0.682689492137086
>>> erfc(1.0/sqrt(2.0)) # portion of normal distribution outside 1 standard deviation
0.31731050786291404
>>> erf(1.0/sqrt(2.0)) + erfc(1.0/sqrt(2.0))
1.0

The :func:`~math.gamma` function is a continuous extension of the factorial
function. See https://en.wikipedia.org/wiki/Gamma_function for details. Because
Expand Down Expand Up @@ -1384,7 +1387,7 @@ guaranteed not to block when :func:`select.select` says a pipe is ready
for writing.

>>> import select
>>> select.PIPE_BUF
>>> select.PIPE_BUF # doctest: +SKIP
512

(Available on Unix systems. Patch by Sébastien Sablé in :issue:`9862`)
Expand Down