[Python-checkins] cpython (3.6): Fixes #29133: clarified shlex documentation.

vinay.sajip python-checkins at python.org
Mon Jan 9 11:48:39 EST 2017


https://hg.python.org/cpython/rev/af5b34b2d169
changeset:   106070:af5b34b2d169
branch:      3.6
parent:      106065:1b767f2ff2c0
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Mon Jan 09 16:46:04 2017 +0000
summary:
  Fixes #29133: clarified shlex documentation.

files:
  Doc/library/shlex.rst |  26 +++++++++++---------------
  1 files changed, 11 insertions(+), 15 deletions(-)


diff --git a/Doc/library/shlex.rst b/Doc/library/shlex.rst
--- a/Doc/library/shlex.rst
+++ b/Doc/library/shlex.rst
@@ -374,23 +374,19 @@
 this is short of a full parser for shells (which would be out of scope for the
 standard library, given the multiplicity of shells out there), it does allow
 you to perform processing of command lines more easily than you could
-otherwise.  To illustrate, you can see the difference in the following snippet::
+otherwise.  To illustrate, you can see the difference in the following snippet:
 
-    import shlex
+.. doctest::
+   :options: +NORMALIZE_WHITESPACE
 
-    for punct in (False, True):
-        if punct:
-            message = 'Old'
-        else:
-            message = 'New'
-        text = "a && b; c && d || e; f >'abc'; (def \"ghi\")"
-        s = shlex.shlex(text, punctuation_chars=punct)
-        print('%s: %s' % (message, list(s)))
-
-which prints out::
-
-    Old: ['a', '&', '&', 'b', ';', 'c', '&', '&', 'd', '|', '|', 'e', ';', 'f', '>', "'abc'", ';', '(', 'def', '"ghi"', ')']
-    New: ['a', '&&', 'b', ';', 'c', '&&', 'd', '||', 'e', ';', 'f', '>', "'abc'", ';', '(', 'def', '"ghi"', ')']
+    >>> import shlex
+    >>> text = "a && b; c && d || e; f >'abc'; (def \"ghi\")"
+    >>> list(shlex.shlex(text))
+    ['a', '&', '&', 'b', ';', 'c', '&', '&', 'd', '|', '|', 'e', ';', 'f', '>',
+    "'abc'", ';', '(', 'def', '"ghi"', ')']
+    >>> list(shlex.shlex(text, punctuation_chars=True))
+    ['a', '&&', 'b', ';', 'c', '&&', 'd', '||', 'e', ';', 'f', '>', "'abc'",
+    ';', '(', 'def', '"ghi"', ')']
 
 Of course, tokens will be returned which are not valid for shells, and you'll
 need to implement your own error checks on the returned tokens.

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list