summaryrefslogtreecommitdiff
path: root/cmd2/history.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-29 12:27:46 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-29 12:30:17 -0400
commit2500f39521bf5e5bab3a63468e88699310bad47e (patch)
treedff0caebe2904bdfe19b5ad5678741d7b2fa1dc9 /cmd2/history.py
parent070262e1f397e2297cdb1ad611db6b6d5bed8830 (diff)
downloadcmd2-git-ordered_history.tar.gz
Changed History to use OrderDict to support Python 3.6 in non-CPython environments.ordered_history
Diffstat (limited to 'cmd2/history.py')
-rw-r--r--cmd2/history.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/cmd2/history.py b/cmd2/history.py
index 78377c06..3a2a9ed5 100644
--- a/cmd2/history.py
+++ b/cmd2/history.py
@@ -4,9 +4,11 @@ History management classes
"""
import re
+from collections import (
+ OrderedDict,
+)
from typing import (
Callable,
- Dict,
Optional,
Union,
)
@@ -173,7 +175,7 @@ class History(list):
#
spanpattern = re.compile(r'^\s*(?P<start>-?[1-9]\d*)?(?P<separator>:|(\.{2,}))(?P<end>-?[1-9]\d*)?\s*$')
- def span(self, span: str, include_persisted: bool = False) -> Dict[int, HistoryItem]:
+ def span(self, span: str, include_persisted: bool = False) -> 'OrderedDict[int, HistoryItem]':
"""Return a slice of the History list
:param span: string containing an index or a slice
@@ -222,7 +224,7 @@ class History(list):
return self._build_result_dictionary(start, end)
- def str_search(self, search: str, include_persisted: bool = False) -> Dict[int, HistoryItem]:
+ def str_search(self, search: str, include_persisted: bool = False) -> 'OrderedDict[int, HistoryItem]':
"""Find history items which contain a given string
:param search: the string to search for
@@ -241,7 +243,7 @@ class History(list):
start = 0 if include_persisted else self.session_start_index
return self._build_result_dictionary(start, len(self), isin)
- def regex_search(self, regex: str, include_persisted: bool = False) -> Dict[int, HistoryItem]:
+ def regex_search(self, regex: str, include_persisted: bool = False) -> 'OrderedDict[int, HistoryItem]':
"""Find history items which match a given regular expression
:param regex: the regular expression to search for.
@@ -277,13 +279,13 @@ class History(list):
def _build_result_dictionary(
self, start: int, end: int, filter_func: Optional[Callable[[HistoryItem], bool]] = None
- ) -> Dict[int, HistoryItem]:
+ ) -> 'OrderedDict[int, HistoryItem]':
"""
Build history search results
:param start: start index to search from
:param end: end index to stop searching (exclusive)
"""
- results: Dict[int, HistoryItem] = dict()
+ results: OrderedDict[int, HistoryItem] = OrderedDict()
for index in range(start, end):
if filter_func is None or filter_func(self[index]):
results[index + 1] = self[index]