Пример #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
Пример #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
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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\\'])
Пример #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"])
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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"])
Пример #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\\'])
Пример #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\\'])
Пример #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\\'])