From ef73f53b2bc67b8374586d10cd530164a219ebf7 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Sat, 11 Mar 2017 12:58:16 +0100 Subject: [PATCH 01/11] bpo-27200: fix pathlib.rst doctests. --- Doc/library/pathlib.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 34ab3b8edf962b6..5b748db8b7bb27f 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -46,7 +46,7 @@ Pure paths are useful in some special cases; for example: Basic use --------- -Importing the main class:: +Importing the main class: >>> from pathlib import Path @@ -271,6 +271,10 @@ property: Methods and properties ^^^^^^^^^^^^^^^^^^^^^^ +.. testsetup:: + + from pathlib import PurePosixPath, PureWindowsPath + Pure paths provide the following methods and properties: .. data:: PurePath.drive @@ -655,7 +659,7 @@ call fails (for example because the path doesn't exist): .. method:: Path.stat() Return information about this path (similarly to :func:`os.stat`). - The result is looked up at each call to this method. + The result is looked up at each call to this method. :: >>> p = Path('setup.py') >>> p.stat().st_size @@ -948,7 +952,7 @@ call fails (for example because the path doesn't exist): .. method:: Path.rglob(pattern) This is like calling :meth:`Path.glob` with "``**``" added in front of the - given *pattern*: + given *pattern*:: >>> sorted(Path().rglob("*.py")) [PosixPath('build/lib/pathlib.py'), @@ -970,7 +974,7 @@ call fails (for example because the path doesn't exist): to :func:`os.path.samefile` and :func:`os.path.samestat`. An :exc:`OSError` can be raised if either file cannot be accessed for some - reason. + reason. :: >>> p = Path('spam') >>> q = Path('eggs') @@ -986,7 +990,7 @@ call fails (for example because the path doesn't exist): Make this path a symbolic link to *target*. Under Windows, *target_is_directory* must be true (default ``False``) if the link's target - is a directory. Under POSIX, *target_is_directory*'s value is ignored. + is a directory. Under POSIX, *target_is_directory*'s value is ignored. :: >>> p = Path('mylink') >>> p.symlink_to('setup.py') From 8332ecfafa5d6cc72fcb24ed9dce9d9df72ddd13 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Sat, 11 Mar 2017 13:01:35 +0100 Subject: [PATCH 02/11] bpo-27200: fix shlex.rst doctests. --- Doc/library/shlex.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/shlex.rst b/Doc/library/shlex.rst index 55012f80e8f923f..fb335c690068165 100644 --- a/Doc/library/shlex.rst +++ b/Doc/library/shlex.rst @@ -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: >>> 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 ~' @@ -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 ~'"] From b88124beee45f8432055aaf210f5e3b4e2a19a8f Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Sat, 11 Mar 2017 13:13:09 +0100 Subject: [PATCH 03/11] bpo-27200: fix ssl.rst doctests. --- Doc/library/ssl.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst index bbb13745b203e6e..01dbecd7e390eb8 100644 --- a/Doc/library/ssl.rst +++ b/Doc/library/ssl.rst @@ -369,6 +369,10 @@ Random generation Certificate handling ^^^^^^^^^^^^^^^^^^^^ +.. testsetup:: + + import ssl + .. function:: match_hostname(cert, hostname) Verify that *cert* (in decoded format as returned by @@ -1378,6 +1382,7 @@ to speed up repeated connections from the same clients. 'strength_bits': 128}] On OpenSSL 1.1 and newer the cipher dict contains additional fields:: + >>> ctx.get_ciphers() # OpenSSL 1.1+ [{'aead': True, 'alg_bits': 256, @@ -1638,7 +1643,7 @@ to speed up repeated connections from the same clients. .. versionchanged:: 3.6 :attr:`SSLContext.options` returns :class:`Options` flags: - >>> ssl.create_default_context().options + >>> ssl.create_default_context().options # doctest: +SKIP .. attribute:: SSLContext.protocol @@ -1658,7 +1663,7 @@ to speed up repeated connections from the same clients. .. versionchanged:: 3.6 :attr:`SSLContext.verify_flags` returns :class:`VerifyFlags` flags: - >>> ssl.create_default_context().verify_flags + >>> ssl.create_default_context().verify_flags # doctest: +SKIP .. attribute:: SSLContext.verify_mode From 9708d8ed5c5e4b96ecbf13d24a17a249b2c49eb0 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Sat, 11 Mar 2017 13:17:44 +0100 Subject: [PATCH 04/11] bpo-27200: fix turtle.rst doctests. --- Doc/library/turtle.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index 1986972549c503d..6f2626cef24bdc9 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -936,10 +936,9 @@ Color control >>> turtle.fillcolor("violet") >>> turtle.fillcolor() 'violet' - >>> col = turtle.pencolor() - >>> col + >>> turtle.pencolor() (50.0, 193.0, 143.0) - >>> turtle.fillcolor(col) + >>> turtle.fillcolor((50, 193, 143)) # Integers, not floats >>> turtle.fillcolor() (50.0, 193.0, 143.0) >>> turtle.fillcolor('#ffffff') From 52351e1dac6c82fb80228be67d6e823297a8aabf Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Sat, 11 Mar 2017 13:28:47 +0100 Subject: [PATCH 05/11] bpo-27200: fix weakref.rst doctests. --- Doc/library/weakref.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst index b02a006d733b6e2..40bb06adfd447e9 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -478,7 +478,7 @@ the constructor when it was created. >>> obj = Object() >>> f = weakref.finalize(obj, callback, 1, 2, z=3) >>> f.detach() #doctest:+ELLIPSIS - (<__main__.Object object ...>, , (1, 2), {'z': 3}) + (<...Object object ...>, , (1, 2), {'z': 3}) >>> newobj, func, args, kwargs = _ >>> assert not f.alive >>> assert newobj is obj From 6ca705b5288bbca9553bef437c8e16dc1e7e9283 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Sun, 12 Mar 2017 17:36:15 +0100 Subject: [PATCH 06/11] bpo-27200: at the end of the tests the context has to be left clean. The setcontext(Context()) in testsetup does not guarantee that the tests outside this file have a clean context. We need to clean the context at the end of the tests. --- Doc/library/decimal.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index e984edcb75421b6..649fe5f2b95d868 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -23,6 +23,11 @@ # make sure each group gets a fresh context setcontext(Context()) +.. testcleanup:: * + + # make sure other tests (also outside this file) get a fresh context + setcontext(Context()) + -------------- The :mod:`decimal` module provides support for fast correctly-rounded @@ -178,6 +183,11 @@ The significance of a new Decimal is determined solely by the number of digits input. Context precision and rounding only come into play during arithmetic operations. +.. testcleanup:: newcontext + + # make sure other tests (also outside this file) get a fresh context + setcontext(Context()) + .. doctest:: newcontext >>> getcontext().prec = 6 From 864b0b70a5da9a3b286647009a410e7b3add7417 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Wed, 12 Apr 2017 17:44:29 +0200 Subject: [PATCH 07/11] Remove decimal.rst from this PR --- Doc/library/decimal.rst | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 649fe5f2b95d868..e984edcb75421b6 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -23,11 +23,6 @@ # make sure each group gets a fresh context setcontext(Context()) -.. testcleanup:: * - - # make sure other tests (also outside this file) get a fresh context - setcontext(Context()) - -------------- The :mod:`decimal` module provides support for fast correctly-rounded @@ -183,11 +178,6 @@ The significance of a new Decimal is determined solely by the number of digits input. Context precision and rounding only come into play during arithmetic operations. -.. testcleanup:: newcontext - - # make sure other tests (also outside this file) get a fresh context - setcontext(Context()) - .. doctest:: newcontext >>> getcontext().prec = 6 From 989fd6cac333bcc39c427f2b0d41e82155fec326 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Wed, 12 Apr 2017 18:49:16 +0200 Subject: [PATCH 08/11] bpo-27200: revert change in pathlib.rst --- Doc/library/pathlib.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 5b748db8b7bb27f..1c1942598d1b79b 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -46,7 +46,7 @@ Pure paths are useful in some special cases; for example: Basic use --------- -Importing the main class: +Importing the main class:: >>> from pathlib import Path From 43744f3233b46b1c6aa9d7f272ef2f0bcf0c19ad Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Wed, 12 Apr 2017 18:50:19 +0200 Subject: [PATCH 09/11] bpo-27200: revert change in shlex.rst --- Doc/library/shlex.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Doc/library/shlex.rst b/Doc/library/shlex.rst index fb335c690068165..55012f80e8f923f 100644 --- a/Doc/library/shlex.rst +++ b/Doc/library/shlex.rst @@ -43,16 +43,15 @@ 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:: >>> 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 ~' @@ -62,7 +61,6 @@ 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 ~'"] From 40a3875b9b6dfda87b274c5273ce4cfca425f2c9 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Wed, 12 Apr 2017 18:50:53 +0200 Subject: [PATCH 10/11] bpo-27200: skip more tests in ssl.rst --- Doc/library/ssl.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst index 01dbecd7e390eb8..e00b3d770411ee5 100644 --- a/Doc/library/ssl.rst +++ b/Doc/library/ssl.rst @@ -419,10 +419,10 @@ Certificate handling >>> import ssl >>> timestamp = ssl.cert_time_to_seconds("Jan 5 09:34:43 2018 GMT") - >>> timestamp + >>> timestamp # doctest: +SKIP 1515144883 >>> from datetime import datetime - >>> print(datetime.utcfromtimestamp(timestamp)) + >>> print(datetime.utcfromtimestamp(timestamp)) # doctest: +SKIP 2018-01-05 09:34:43 "notBefore" or "notAfter" dates must use GMT (:rfc:`5280`). @@ -2262,7 +2262,7 @@ SSL versions 2 and 3 are considered insecure and are therefore dangerous to use. If you want maximum compatibility between clients and servers, it is recommended to use :const:`PROTOCOL_TLS_CLIENT` or :const:`PROTOCOL_TLS_SERVER` as the protocol version. SSLv2 and SSLv3 are -disabled by default. +disabled by default. :: >>> client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) >>> client_context.options |= ssl.OP_NO_TLSv1 From 4d63142458a72bb7ac61ef871f1d0e8aff86c277 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Thu, 13 Apr 2017 10:40:14 +0200 Subject: [PATCH 11/11] bpo-27200: move the :: on a new line. --- Doc/library/pathlib.rst | 12 +++++++++--- Doc/library/ssl.rst | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 1c1942598d1b79b..14452264472af16 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -659,7 +659,9 @@ call fails (for example because the path doesn't exist): .. method:: Path.stat() Return information about this path (similarly to :func:`os.stat`). - The result is looked up at each call to this method. :: + The result is looked up at each call to this method. + + :: >>> p = Path('setup.py') >>> p.stat().st_size @@ -974,7 +976,9 @@ call fails (for example because the path doesn't exist): to :func:`os.path.samefile` and :func:`os.path.samestat`. An :exc:`OSError` can be raised if either file cannot be accessed for some - reason. :: + reason. + + :: >>> p = Path('spam') >>> q = Path('eggs') @@ -990,7 +994,9 @@ call fails (for example because the path doesn't exist): Make this path a symbolic link to *target*. Under Windows, *target_is_directory* must be true (default ``False``) if the link's target - is a directory. Under POSIX, *target_is_directory*'s value is ignored. :: + is a directory. Under POSIX, *target_is_directory*'s value is ignored. + + :: >>> p = Path('mylink') >>> p.symlink_to('setup.py') diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst index e00b3d770411ee5..e3945191f53248c 100644 --- a/Doc/library/ssl.rst +++ b/Doc/library/ssl.rst @@ -2262,7 +2262,9 @@ SSL versions 2 and 3 are considered insecure and are therefore dangerous to use. If you want maximum compatibility between clients and servers, it is recommended to use :const:`PROTOCOL_TLS_CLIENT` or :const:`PROTOCOL_TLS_SERVER` as the protocol version. SSLv2 and SSLv3 are -disabled by default. :: +disabled by default. + +:: >>> client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) >>> client_context.options |= ssl.OP_NO_TLSv1