Esempio n. 1
0
 def _split_args(self, argstr):
     """Split the arguments from an arg string."""
     if argstr is None:
         self._args = []
     elif self._cmd.split:
         self._args = utils.safe_shlex_split(argstr)
     else:
         # If split=False, we still want to split the flags, but not
         # everything after that.
         # We first split the arg string and check the index of the first
         # non-flag args, then we re-split again properly.
         # example:
         #
         # input: "--foo -v bar baz"
         # first split: ['--foo', '-v', 'bar', 'baz']
         #                0        1     2      3
         # second split: ['--foo', '-v', 'bar baz']
         # (maxsplit=2)
         split_args = argstr.split()
         for i, arg in enumerate(split_args):
             if not arg.startswith('-'):
                 self._args = argstr.split(maxsplit=i)
                 break
         else:
             # If there are only flags, we got it right on the first try
             # already.
             self._args = split_args
Esempio n. 2
0
 def _split_args(self, argstr):
     """Split the arguments from an arg string."""
     if argstr is None:
         self._args = []
     elif self._cmd.split:
         self._args = utils.safe_shlex_split(argstr)
     else:
         # If split=False, we still want to split the flags, but not
         # everything after that.
         # We first split the arg string and check the index of the first
         # non-flag args, then we re-split again properly.
         # example:
         #
         # input: "--foo -v bar baz"
         # first split: ['--foo', '-v', 'bar', 'baz']
         #                0        1     2      3
         # second split: ['--foo', '-v', 'bar baz']
         # (maxsplit=2)
         split_args = argstr.split()
         for i, arg in enumerate(split_args):
             if not arg.startswith('-'):
                 self._args = argstr.split(maxsplit=i)
                 break
         else:
             # If there are only flags, we got it right on the first try
             # already.
             self._args = split_args
Esempio n. 3
0
 def test_escaped_single(self):
     """Test safe_shlex_split with a single escaped string."""
     items = utils.safe_shlex_split(r"one 'two'\'' three' four")
     self.assertEqual(items, ['one', "two' three", 'four'])
Esempio n. 4
0
 def test_escaped(self):
     """Test safe_shlex_split with a normal escaped string."""
     items = utils.safe_shlex_split(r'one "two\" three" four')
     self.assertEqual(items, ['one', 'two" three', 'four'])
Esempio n. 5
0
 def test_single_quoted(self):
     """Test safe_shlex_split with a single quoted string."""
     items = utils.safe_shlex_split("one 'two three' four")
     self.assertEqual(items, ['one', 'two three', 'four'])
Esempio n. 6
0
 def test_quoted(self):
     """Test safe_shlex_split with a normally quoted string."""
     items = utils.safe_shlex_split('one "two three" four')
     self.assertEqual(items, ['one', 'two three', 'four'])
Esempio n. 7
0
 def test_normal(self):
     """Test safe_shlex_split with a simple string."""
     items = utils.safe_shlex_split('one two')
     self.assertEqual(items, ['one', 'two'])
Esempio n. 8
0
 def test_unfinished_escape(self):
     """Test safe_shlex_split with an unfinished escape."""
     items = utils.safe_shlex_split('one\\')
     self.assertEqual(items, ['one\\'])
Esempio n. 9
0
 def test_unbalanced_single_quotes(self):
     """Test safe_shlex_split with unbalanded single quotes."""
     items = utils.safe_shlex_split(r"one 'two three")
     self.assertEqual(items, ['one', "two three"])
Esempio n. 10
0
 def test_unbalanced_quotes(self):
     """Test safe_shlex_split with unbalanded quotes."""
     items = utils.safe_shlex_split(r'one "two three')
     self.assertEqual(items, ['one', 'two three'])
Esempio n. 11
0
 def test_escaped_single(self):
     """Test safe_shlex_split with a single escaped string."""
     items = utils.safe_shlex_split(r"one 'two'\'' three' four")
     self.assertEqual(items, ['one', "two' three", 'four'])
Esempio n. 12
0
 def test_escaped(self):
     """Test safe_shlex_split with a normal escaped string."""
     items = utils.safe_shlex_split(r'one "two\" three" four')
     self.assertEqual(items, ['one', 'two" three', 'four'])
Esempio n. 13
0
 def test_single_quoted(self):
     """Test safe_shlex_split with a single quoted string."""
     items = utils.safe_shlex_split("one 'two three' four")
     self.assertEqual(items, ['one', 'two three', 'four'])
Esempio n. 14
0
 def test_quoted(self):
     """Test safe_shlex_split with a normally quoted string."""
     items = utils.safe_shlex_split('one "two three" four')
     self.assertEqual(items, ['one', 'two three', 'four'])
Esempio n. 15
0
 def test_normal(self):
     """Test safe_shlex_split with a simple string."""
     items = utils.safe_shlex_split('one two')
     self.assertEqual(items, ['one', 'two'])
Esempio n. 16
0
 def test_unbalanced_quotes(self):
     """Test safe_shlex_split with unbalanded quotes."""
     items = utils.safe_shlex_split(r'one "two three')
     self.assertEqual(items, ['one', 'two three'])
Esempio n. 17
0
 def test_unbalanced_single_quotes(self):
     """Test safe_shlex_split with unbalanded single quotes."""
     items = utils.safe_shlex_split(r"one 'two three")
     self.assertEqual(items, ['one', "two three"])
Esempio n. 18
0
 def test_unfinished_escape(self):
     """Test safe_shlex_split with an unfinished escape."""
     items = utils.safe_shlex_split('one\\')
     self.assertEqual(items, ['one\\'])
Esempio n. 19
0
 def test_both(self):
     """Test safe_shlex_split with an unfinished escape and quotes.."""
     items = utils.safe_shlex_split('one "two\\')
     self.assertEqual(items, ['one', 'two\\'])
Esempio n. 20
0
 def test_both(self):
     """Test safe_shlex_split with an unfinished escape and quotes.."""
     items = utils.safe_shlex_split('one "two\\')
     self.assertEqual(items, ['one', 'two\\'])