From bbaab24ce8e3754987b328951f115204236cca5e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 16 Nov 2015 20:24:27 +0100 Subject: [PATCH] Fix lint. --- qutebrowser/commands/runners.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/qutebrowser/commands/runners.py b/qutebrowser/commands/runners.py index 84f358682..23eba1f49 100644 --- a/qutebrowser/commands/runners.py +++ b/qutebrowser/commands/runners.py @@ -118,6 +118,26 @@ class CommandRunner(QObject): for sub in sub_texts: yield self.parse(sub, *args, **kwargs) + def _parse_count(self, cmdstr): + """Split a count prefix off from a command for parse(). + + Args: + cmdstr: The command/args including the count. + + Return: + A (count, cmdstr) tuple, with count being None or int. + """ + if ':' not in cmdstr: + return (None, cmdstr) + + count, cmdstr = cmdstr.split(':', maxsplit=1) + try: + count = int(count) + except ValueError: + # We just ignore invalid prefixes + count = None + return (count, cmdstr) + def parse(self, text, *, aliases=True, fallback=False, keep=False): """Split the commandline text into command and arguments. @@ -132,15 +152,7 @@ class CommandRunner(QObject): A ParseResult tuple. """ cmdstr, sep, argstr = text.partition(' ') - if ':' in cmdstr: - count, cmdstr = cmdstr.split(':', maxsplit=1) - try: - count = int(count) - except ValueError as e: - # We just ignore invalid prefixes - count = None - else: - count = None + count, cmdstr = self._parse_count(cmdstr) if not cmdstr and not fallback: raise cmdexc.NoSuchCommandError("No command given")