summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2017-01-09 16:48:23 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2017-01-09 16:48:23 (GMT)
commitb5c557929ec6e3a9b0e6842500155e63c9aa23a3 (patch)
tree51dbf4280749a7f08a042590ea5bcf184e6d8703
parent605a4476f85f97ae274670b56d6d1d750f49cb4c (diff)
parentaa655b3a8e8607c71ee801dfac8e10486cdb6305 (diff)
downloadcpython-b5c557929ec6e3a9b0e6842500155e63c9aa23a3.zip
cpython-b5c557929ec6e3a9b0e6842500155e63c9aa23a3.tar.gz
cpython-b5c557929ec6e3a9b0e6842500155e63c9aa23a3.tar.bz2
Closes #29133: merged update from 3.6.
Thanks to Evan_ for the report and Marco Buttu for the patch.
-rw-r--r--Doc/library/shlex.rst26
1 files changed, 11 insertions, 15 deletions
diff --git a/Doc/library/shlex.rst b/Doc/library/shlex.rst
index 1a89bf6..4926f04 100644
--- a/Doc/library/shlex.rst
+++ b/Doc/library/shlex.rst
@@ -374,23 +374,19 @@ is changed: any run of these characters is returned as a single token. While
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.