Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
48f3dcc9
Commit
48f3dcc9
authored
Apr 20, 2003
by
Gustavo Niemeyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Changed shlex.split() method to have more useful and
meaningful parameters.
parent
cf146d31
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
16 deletions
+13
-16
Doc/lib/libshlex.tex
Doc/lib/libshlex.tex
+5
-6
Lib/shlex.py
Lib/shlex.py
+5
-3
Lib/test/test_shlex.py
Lib/test/test_shlex.py
+3
-7
No files found.
Doc/lib/libshlex.tex
View file @
48f3dcc9
...
...
@@ -25,12 +25,11 @@ Python applications) or for parsing quoted strings.
The
\module
{
shlex
}
module defines the following functions:
\begin{funcdesc}
{
split
}{
s
\optional
{
, posix=
\code
{
True
}
\optional
{
,
spaces=
\code
{
True
}}}}
Split the string
\var
{
s
}
using shell-like syntax. If
\var
{
posix
}
is
\code
{
True
}
, operate in
\POSIX
{}
mode. If
\var
{
spaces
}
is
\code
{
True
}
, it
will only split words in whitespaces (setting the
\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.
\versionadded
{
2.3
}
\end{funcdesc}
...
...
Lib/shlex.py
View file @
48f3dcc9
...
...
@@ -271,9 +271,11 @@ class shlex:
raise
StopIteration
return
token
def
split
(
s
,
posix
=
True
,
spaces
=
True
):
lex
=
shlex
(
s
,
posix
=
posix
)
lex
.
whitespace_split
=
spaces
def
split
(
s
,
comments
=
False
):
lex
=
shlex
(
s
,
posix
=
True
)
lex
.
whitespace_split
=
True
if
not
comments
:
lex
.
commenters
=
''
return
list
(
lex
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_shlex.py
View file @
48f3dcc9
...
...
@@ -151,9 +151,9 @@ class ShlexTest(unittest.TestCase):
for
item
in
self
.
posix_data
:
item
[
0
]
=
item
[
0
].
replace
(
r"\n"
,
"
\
n
"
)
def
splitTest
(
self
,
data
,
posix
,
space
s
):
def
splitTest
(
self
,
data
,
comment
s
):
for
i
in
range
(
len
(
data
)):
l
=
shlex
.
split
(
data
[
i
][
0
],
posix
=
posix
,
spaces
=
space
s
)
l
=
shlex
.
split
(
data
[
i
][
0
],
comments
=
comment
s
)
self
.
assertEqual
(
l
,
data
[
i
][
1
:],
"%s: %s != %s"
%
(
data
[
i
][
0
],
l
,
data
[
i
][
1
:]))
...
...
@@ -167,13 +167,9 @@ class ShlexTest(unittest.TestCase):
tok
=
lex
.
get_token
()
return
ret
def
testSplit
(
self
):
"""Test data splitting with non-posix parser"""
self
.
splitTest
(
self
.
data
,
posix
=
0
,
spaces
=
0
)
def
testSplitPosix
(
self
):
"""Test data splitting with posix parser"""
self
.
splitTest
(
self
.
posix_data
,
posix
=
1
,
spaces
=
1
)
self
.
splitTest
(
self
.
posix_data
,
comments
=
True
)
def
testCompat
(
self
):
"""Test compatibility interface"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment