diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2003-04-20 01:57:03 (GMT) |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2003-04-20 01:57:03 (GMT) |
commit | 48f3dcc93e57e75e43f9e1a82daa02d2c2f29ec8 (patch) | |
tree | 565d184f58251dabce4907b80cf999593d888c17 /Lib | |
parent | cf146d31e72467db55a97169563c813706cef681 (diff) | |
download | cpython-48f3dcc93e57e75e43f9e1a82daa02d2c2f29ec8.zip cpython-48f3dcc93e57e75e43f9e1a82daa02d2c2f29ec8.tar.gz cpython-48f3dcc93e57e75e43f9e1a82daa02d2c2f29ec8.tar.bz2 |
- Changed shlex.split() method to have more useful and
meaningful parameters.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/shlex.py | 8 | ||||
-rw-r--r-- | Lib/test/test_shlex.py | 10 |
2 files changed, 8 insertions, 10 deletions
diff --git a/Lib/shlex.py b/Lib/shlex.py index dd10447..b302699 100644 --- a/Lib/shlex.py +++ b/Lib/shlex.py @@ -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__': diff --git a/Lib/test/test_shlex.py b/Lib/test/test_shlex.py index ed0ab47..1678c7d 100644 --- a/Lib/test/test_shlex.py +++ b/Lib/test/test_shlex.py @@ -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, spaces): + def splitTest(self, data, comments): for i in range(len(data)): - l = shlex.split(data[i][0], posix=posix, spaces=spaces) + l = shlex.split(data[i][0], comments=comments) 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""" |