]> granicus.if.org Git - python/commitdiff
- Changed shlex.split() method to have more useful and
authorGustavo Niemeyer <gustavo@niemeyer.net>
Sun, 20 Apr 2003 01:57:03 +0000 (01:57 +0000)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Sun, 20 Apr 2003 01:57:03 +0000 (01:57 +0000)
  meaningful parameters.

Doc/lib/libshlex.tex
Lib/shlex.py
Lib/test/test_shlex.py

index 9ebe16b36bfbce050a249cfbd2951f99d959f995..56125d3e1a335fc9923f9e6806e484241f041f44 100644 (file)
@@ -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}
 
index dd104472f690a7ba5928d49c3760676645eeb96f..b302699c7629f612c0ee76c674ef584acbca6d4c 100644 (file)
@@ -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__':
index ed0ab47b1819ca0fcf3f6116bf679bf4ea77d6a3..1678c7d3b18bb466c18dbb3816d128a1db89b38f 100644 (file)
@@ -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"""