diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-09-28 15:01:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-28 15:01:10 -0400 |
commit | 87fdda149ade5c82d853334c87db0a2d11445594 (patch) | |
tree | ae42eff9d6a906550c5a4f83144b4bbd6d04dba5 /cmd2/utils.py | |
parent | bb8f6dd930820ef580d3399726256ac0a19a78dc (diff) | |
parent | 2cbc5cf234a353b94740f167b5b8564bbd2fc900 (diff) | |
download | cmd2-git-87fdda149ade5c82d853334c87db0a2d11445594.tar.gz |
Merge pull request #550 from python-cmd2/macro
Added macros
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index bdb488cc..ddd43507 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -6,7 +6,7 @@ import collections import os import re import unicodedata -from typing import Any, List, Optional, Union +from typing import Any, Iterable, List, Optional, Union from . import constants @@ -194,7 +194,7 @@ def norm_fold(astr: str) -> str: return unicodedata.normalize('NFC', astr).casefold() -def alphabetical_sort(list_to_sort: List[str]) -> List[str]: +def alphabetical_sort(list_to_sort: Iterable[str]) -> List[str]: """Sorts a list of strings alphabetically. For example: ['a1', 'A11', 'A2', 'a22', 'a3'] @@ -229,10 +229,10 @@ def natural_keys(input_str: str) -> List[Union[int, str]]: :param input_str: string to convert :return: list of strings and integers """ - return [try_int_or_force_to_lower_case(substr) for substr in re.split('(\d+)', input_str)] + return [try_int_or_force_to_lower_case(substr) for substr in re.split(r'(\d+)', input_str)] -def natural_sort(list_to_sort: List[str]) -> List[str]: +def natural_sort(list_to_sort: Iterable[str]) -> List[str]: """ Sorts a list of strings case insensitively as well as numerically. @@ -304,3 +304,15 @@ class StdSim(object): return self.__dict__[item] else: return getattr(self.inner_stream, item) + + +def unquote_redirection_tokens(args: List[str]) -> None: + """ + Unquote redirection tokens in a list of command-line arguments + This is used when redirection tokens have to be passed to another command + :param args: the command line args + """ + for i, arg in enumerate(args): + unquoted_arg = strip_quotes(arg) + if unquoted_arg in constants.REDIRECTION_TOKENS: + args[i] = unquoted_arg |