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


Python split.split函数代码示例

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


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

示例1: test_split_keep

 def test_split_keep(self):
     """Test splitting with keep=True."""
     for case in test_data.strip().splitlines():
         cmd, _mid, out = case.split('/')[:-1]
         with self.subTest(cmd=cmd):
             items = split.split(cmd, keep=True)
             self.assertEqual(items, out.split('|'))
开发者ID:JIVS,项目名称:qutebrowser,代码行数:7,代码来源:test_split.py

示例2: test_split_keep_original

 def test_split_keep_original(self):
     """Test if splitting with keep=True yields the original string."""
     for case in test_data.strip().splitlines():
         cmd = case.split('/')[0]
         with self.subTest(cmd=cmd):
             items = split.split(cmd, keep=True)
             self.assertEqual(''.join(items), cmd)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:7,代码来源:test_split.py

示例3: test_split

 def test_split(self):
     """Test splitting."""
     for case in test_data.strip().splitlines():
         cmd, out = case.split('/')[:-2]
         with self.subTest(cmd=cmd):
             items = split.split(cmd)
             self.assertEqual(items, out.split('|'))
开发者ID:JIVS,项目名称:qutebrowser,代码行数:7,代码来源:test_split.py

示例4: _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

示例5: _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

示例6: parse

    def parse(self, text, *, fallback=False, keep=False):
        """Split the commandline text into command and arguments.

        Args:
            text: Text to parse.
            fallback: Whether to do a fallback splitting when the command was
                      unknown.
            keep: Whether to keep special chars and whitespace

        Return:
            A ParseResult tuple.
        """
        cmdstr, sep, argstr = text.partition(' ')
        count, cmdstr = self._parse_count(cmdstr)

        if not cmdstr and not fallback:
            raise cmdexc.NoSuchCommandError("No command given")

        if self._partial_match:
            cmdstr = self._completion_match(cmdstr)

        try:
            cmd = cmdutils.cmd_dict[cmdstr]
        except KeyError:
            if not fallback:
                raise cmdexc.NoSuchCommandError(
                    '{}: no such command'.format(cmdstr))
            cmdline = split.split(text, keep=keep)
            return ParseResult(cmd=None, args=None, cmdline=cmdline,
                               count=count)

        args = self._split_args(cmd, argstr, keep)
        if keep and args:
            cmdline = [cmdstr, sep + args[0]] + args[1:]
        elif keep:
            cmdline = [cmdstr, sep]
        else:
            cmdline = [cmdstr] + args[:]

        return ParseResult(cmd=cmd, args=args, cmdline=cmdline, count=count)
开发者ID:Dietr1ch,项目名称:qutebrowser,代码行数:40,代码来源:runners.py

示例7: test_split

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

示例8: test_split_keep

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

示例9: test_split_keep_original

 def test_split_keep_original(self, split_test_case):
     """Test if splitting with keep=True yields the original string."""
     items = split.split(split_test_case.inp, keep=True)
     assert ''.join(items) == split_test_case.inp
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:4,代码来源:test_split.py

示例10: test_split

 def test_split(self, split_test_case):
     """Test splitting."""
     items = split.split(split_test_case.inp)
     assert items == split_test_case.keep
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:4,代码来源:test_split.py


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