Skip to content
25 changes: 18 additions & 7 deletions Doc/library/shlex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ The :mod:`!shlex` module defines the following functions:

.. function:: split(s, comments=False, posix=True)

Split the string *s* using shell-like syntax. If *comments* is :const:`False`
(the default), the parsing of comments in the given string will be disabled
(setting the :attr:`~shlex.commenters` attribute of the
Split the string or bytes *s* using shell-like syntax. If *comments* is
:const:`False` (the default), the parsing of comments in the given string
will be disabled (setting the :attr:`~shlex.commenters` attribute of the
:class:`~shlex.shlex` instance to the empty string). This function operates
in POSIX mode by default, but uses non-POSIX mode if the *posix* argument is
false.
Expand All @@ -29,6 +29,9 @@ The :mod:`!shlex` module defines the following functions:
Passing ``None`` for *s* argument now raises an exception, rather than
reading :data:`sys.stdin`.

.. versionchanged:: 3.16
Support bytes as input.

.. function:: join(split_command)

Concatenate the tokens of the list *split_command* and return a string.
Expand All @@ -43,12 +46,15 @@ The :mod:`!shlex` module defines the following functions:

.. versionadded:: 3.8

.. versionchanged:: 3.16
Support sequence of bytes as input.


.. function:: quote(s, *, force=False)

Return a shell-escaped version of the string *s*. The returned value is a
string that can safely be used as one token in a shell command line, for
cases where you cannot use a list.
Return a shell-escaped version of the string or bytes *s*. The returned
value is a string or bytes object that can safely be used as one token in a
shell command line, for cases where you cannot use a list.

If *force* is :const:`True`, then *s* is unconditionally quoted,
even if it is already safe for a shell without being quoted.
Expand Down Expand Up @@ -110,6 +116,7 @@ The :mod:`!shlex` module defines the following functions:

.. versionchanged:: 3.16
The *force* keyword was added.
Support bytes as input.

The :mod:`!shlex` module defines the following class:

Expand All @@ -120,7 +127,8 @@ The :mod:`!shlex` module defines the following class:
object. The initialization argument, if present, specifies where to read
characters from. It must be a file-/stream-like object with
:meth:`~io.TextIOBase.read` and :meth:`~io.TextIOBase.readline` methods, or
a string. If no argument is given, input will be taken from ``sys.stdin``.
a string or a file-like object or bytes. If no argument is given, input
will be taken from ``sys.stdin``.
The second optional argument is a filename string, which sets the initial
value of the :attr:`~shlex.infile` attribute. If the *instream*
argument is omitted or equal to ``sys.stdin``, this second argument
Expand All @@ -144,6 +152,9 @@ The :mod:`!shlex` module defines the following class:
.. versionchanged:: 3.6
The *punctuation_chars* parameter was added.

.. versionchanged:: 3.16
Support bytes or binary IO as *instream*.

.. seealso::

Module :mod:`configparser`
Expand Down
Loading
Loading