Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cf146d3 commit 48f3dccCopy full SHA for 48f3dcc
3 files changed
Doc/lib/libshlex.tex
@@ -25,12 +25,11 @@ \subsection{Module Contents}
25
26
The \module{shlex} module defines the following functions:
27
28
-\begin{funcdesc}{split}{s\optional{, posix=\code{True}\optional{,
29
- spaces=\code{True}}}}
30
-Split the string \var{s} using shell-like syntax. If \var{posix} is
31
-\code{True}, operate in \POSIX{} mode. If \var{spaces} is \code{True}, it
32
-will only split words in whitespaces (setting the
33
-\member{whitespace_split} member of the \class{shlex} instance).
+\begin{funcdesc}{split}{s\optional{, comments=\code{False}}}
+Split the string \var{s} using shell-like syntax. If \var{comments} is
+\code{False}, the parsing of comments in the given string will be
+disabled (setting the \member{commenters} member of the \class{shlex}
+instance to the empty string). This function operates in \POSIX{} mode.
34
\versionadded{2.3}
35
\end{funcdesc}
36
Lib/shlex.py
@@ -271,9 +271,11 @@ def next(self):
271
raise StopIteration
272
return token
273
274
-def split(s, posix=True, spaces=True):
275
- lex = shlex(s, posix=posix)
276
- lex.whitespace_split = spaces
+def split(s, comments=False):
+ lex = shlex(s, posix=True)
+ lex.whitespace_split = True
277
+ if not comments:
278
+ lex.commenters = ''
279
return list(lex)
280
281
if __name__ == '__main__':
Lib/test/test_shlex.py
@@ -151,9 +151,9 @@ def setUp(self):
151
for item in self.posix_data:
152
item[0] = item[0].replace(r"\n", "\n")
153
154
- def splitTest(self, data, posix, spaces):
+ def splitTest(self, data, comments):
155
for i in range(len(data)):
156
- l = shlex.split(data[i][0], posix=posix, spaces=spaces)
+ l = shlex.split(data[i][0], comments=comments)
157
self.assertEqual(l, data[i][1:],
158
"%s: %s != %s" %
159
(data[i][0], l, data[i][1:]))
@@ -167,13 +167,9 @@ def oldSplit(self, s):
167
tok = lex.get_token()
168
return ret
169
170
- def testSplit(self):
171
- """Test data splitting with non-posix parser"""
172
- self.splitTest(self.data, posix=0, spaces=0)
173
-
174
def testSplitPosix(self):
175
"""Test data splitting with posix parser"""
176
- self.splitTest(self.posix_data, posix=1, spaces=1)
+ self.splitTest(self.posix_data, comments=True)
177
178
def testCompat(self):
179
"""Test compatibility interface"""
0 commit comments