当前位置: 首页>>代码示例>>Python>>正文


Python split.simple_split函数代码示例

本文整理汇总了Python中qutebrowser.misc.split.simple_split函数的典型用法代码示例。如果您正苦于以下问题:Python simple_split函数的具体用法?Python simple_split怎么用?Python simple_split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了simple_split函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _split_args

    def _split_args(self, argstr, keep):
        """Split the arguments from an arg string.

        Args:
            argstr: An argument string.
            keep: Whether to keep special chars and whitespace

        Return:
            A list containing the splitted strings.
        """
        if not argstr:
            self._args = []
        elif self._cmd.maxsplit is None:
            self._args = split.split(argstr, keep=keep)
        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 = split.simple_split(argstr, keep=keep)
            flag_arg_count = 0
            for i, arg in enumerate(split_args):
                arg = arg.strip()
                if arg.startswith('-'):
                    if arg.lstrip('-') in self._cmd.flags_with_args:
                        flag_arg_count += 1
                else:
                    self._args = []
                    maxsplit = i + self._cmd.maxsplit + flag_arg_count
                    args = split.simple_split(argstr, keep=keep,
                                              maxsplit=maxsplit)
                    for s in args:
                        # remove quotes and replace \" by "
                        if s == '""' or s == "''":
                            s = ''
                        else:
                            s = re.sub(r"""(^|[^\\])["']""", r'\1', s)
                            s = re.sub(r"""\\(["'])""", r'\1', s)
                        self._args.append(s)
                    break
            else:
                # If there are only flags, we got it right on the first try
                # already.
                self._args = split_args
开发者ID:larryhynes,项目名称:qutebrowser,代码行数:51,代码来源:runners.py

示例2: set_cmd_text_command

    def set_cmd_text_command(self, text, space=False, append=False):
        """Preset the statusbar to some text.

        You can use the `{url}` and `{url:pretty}` variables here which will
        get replaced by the encoded/decoded URL.

        //

        Wrapper for set_cmd_text to check the arguments and allow multiple
        strings which will get joined.

        Args:
            text: The commandline to set.
            space: If given, a space is added to the end.
            append: If given, the text is appended to the current text.
        """
        args = split.simple_split(text)
        args = runners.replace_variables(self._win_id, args)
        text = ' '.join(args)

        if space:
            text += ' '
        if append:
            if not self.text():
                raise cmdexc.CommandError("No current text!")
            text = self.text() + text

        if not text or text[0] not in modeparsers.STARTCHARS:
            raise cmdexc.CommandError(
                "Invalid command text '{}'.".format(text))
        self.set_cmd_text(text)
开发者ID:DoITCreative,项目名称:qutebrowser,代码行数:31,代码来源:command.py

示例3: _split_args

    def _split_args(self, cmd, argstr, keep):
        """Split the arguments from an arg string.

        Args:
            cmd: The command we're currently handling.
            argstr: An argument string.
            keep: Whether to keep special chars and whitespace

        Return:
            A list containing the split strings.
        """
        if not argstr:
            return []
        elif cmd.maxsplit is None:
            return split.split(argstr, keep=keep)
        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 = split.simple_split(argstr, keep=keep)
            flag_arg_count = 0
            for i, arg in enumerate(split_args):
                arg = arg.strip()
                if arg.startswith('-'):
                    if arg in cmd.flags_with_args:
                        flag_arg_count += 1
                else:
                    maxsplit = i + cmd.maxsplit + flag_arg_count
                    return split.simple_split(argstr, keep=keep,
                                              maxsplit=maxsplit)

            # If there are only flags, we got it right on the first try
            # already.
            return split_args
开发者ID:fiete201,项目名称:qutebrowser,代码行数:42,代码来源:runners.py

示例4: test_simple_split

def test_simple_split(keep, maxsplit, s):
    split.simple_split(s, keep=keep, maxsplit=maxsplit)
开发者ID:Harrison97,项目名称:qutebrowser,代码行数:2,代码来源:test_split_hypothesis.py

示例5: test_maxsplit_0_keep

 def test_maxsplit_0_keep(self):
     """Test special case with maxsplit=0 and keep=True."""
     s = "foo  bar"
     assert split.simple_split(s, keep=True, maxsplit=0) == [s]
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:4,代码来源:test_split.py

示例6: test_split_keep

 def test_split_keep(self, test, expected):
     """Test splitting with keep=True."""
     assert split.simple_split(test, keep=True) == expected
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:3,代码来源:test_split.py

示例7: test_str_split_maxsplit

 def test_str_split_maxsplit(self, s, maxsplit):
     """Test if the behavior matches str.split with given maxsplit."""
     actual = split.simple_split(s, maxsplit=maxsplit)
     expected = s.rstrip().split(maxsplit=maxsplit)
     assert actual == expected
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:5,代码来源:test_split.py

示例8: test_str_split

 def test_str_split(self, test):
     """Test if the behavior matches str.split."""
     assert split.simple_split(test) == test.rstrip().split()
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:3,代码来源:test_split.py

示例9: test_split_keep

 def test_split_keep(self):
     """Test splitting with keep=True."""
     for test, expected in self.TESTS.items():
         with self.subTest(string=test):
             self.assertEqual(split.simple_split(test, keep=True), expected)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:5,代码来源:test_split.py

示例10: test_str_split_maxsplit_0

 def test_str_split_maxsplit_0(self):
     """Test if the behavior matches str.split with maxsplit=0."""
     string = "  foo bar baz  "
     self.assertEqual(split.simple_split(string, maxsplit=0),
                      string.rstrip().split(maxsplit=0))
开发者ID:JIVS,项目名称:qutebrowser,代码行数:5,代码来源:test_split.py

示例11: test_str_split

 def test_str_split(self):
     """Test if the behavior matches str.split."""
     for test in self.TESTS:
         with self.subTest(string=test):
             self.assertEqual(split.simple_split(test),
                              test.rstrip().split())
开发者ID:JIVS,项目名称:qutebrowser,代码行数:6,代码来源:test_split.py


注:本文中的qutebrowser.misc.split.simple_split函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。