示例#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\\'])