bronx.stdtypes.history¶
Some types to manage history of commands, actions, etc.
Classes¶
- class bronx.stdtypes.history.History(*args, **kw)[source]¶
Bases:
PrivateHistory,GetByTagShared Multi-purpose history like object.
It is managed by
bronx.patterns.getbytag.GetByTagconsequently a tag parameter needs to be added to the constructor.- Parameters:
queue – Pre-existing history items
maxlen – The maximum size of the history object (see the comment above)
timer – Add a timestamp when showing history entries
- class bronx.stdtypes.history.PrivateHistory(queue=(), maxlen=9999, timer=False)[source]¶
Bases:
objectMulti-purpose history like object.
Items added to an History object are recorded along with a number (starting from 1 and incremented each time an item is added) and a timestamp.
Available history items can be listed searched and printed.
Thanks to the
maxlenparameter, the history object retains only a limited number of items (only themaxlenlatest ones). This mechanism prevent from an excessive memory consumption.Example:
# Initalise an History object that will retain at most 3 entries # (if not specified, default for maxlen is 9999) >>> hst = PrivateHistory(maxlen=3) >>> hst.size 3 # Simply add four entries... >>> hst.append("Entry 1") # doctest: +ELLIPSIS (1, datetime.datetime(...)) >>> len(hst) 1 >>> hst.append("Entry 2") # doctest: +ELLIPSIS (2, datetime.datetime(...)) >>> hst.append("Entry 3") # doctest: +ELLIPSIS (3, datetime.datetime(...)) >>> hst.append("Entry 4", "as a tuple") # doctest: +ELLIPSIS (4, datetime.datetime(...)) # This objects, auto-limits itself to self.size/maxlen >>> len(hst) 3 >>> hst.lower_bound 2 >>> hst.upper_bound 4 # It is iterable and individual elements can be accessed >>> list(hst) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE [(2, datetime.datetime(...), (...'Entry 2',)), (3, datetime.datetime(...), (...'Entry 3',)), (4, datetime.datetime(...), (...'Entry 4', ...'as a tuple'))] >>> hst[3] # doctest: +ELLIPSIS (3, datetime.datetime(...), (...'Entry 3',)) # Simple searches are possible >>> hst.grep('a tup') # doctest: +ELLIPSIS [(4, datetime.datetime(...), (...'Entry 4', ...'as a tuple'))] >>> hst.match(r'En\w+\s+[24]') # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE [(2, datetime.datetime(...), (...'Entry 2',)), (4, datetime.datetime(...), (...'Entry 4', ...'as a tuple'))] # Formatted output are do-able >>> hst.show() [2] : Entry 2 [3] : Entry 3 [4] : Entry 4 as a tuple >>> hst.show(2, 3) [2] : Entry 2 [3] : Entry 3 >>> hst.showgrep('a tup') [4] : Entry 4 as a tuple # With the timestamp >>> hst.timer = True >>> hst.showlast() # doctest: +ELLIPSIS [4][...] : Entry 4 as a tuple
- Parameters:
queue – Pre-existing history items
maxlen – The maximum size of the history object (see the comment above)
timer – Add a timestamp when showing history entries
- around(focus=None, delta=60)[source]¶
Display a numbered list of history items with a stamp value contained in the exclusive interval [
focus-delta,focus+delta].
- property count¶
The current value of the history entry counter.
- get(start=1, end=None)[source]¶
Extract history entries with a count value contained in the inclusive interval
start-end.
- getaround(focus, delta=60)[source]¶
Extract history entries with a stamp value contained in the exclusive interval [
focus-delta,focus+delta].
- property last¶
Return the last history entry.
- property lower_bound¶
The number of oldest history entry retained in the object
- show(start=1, end=None)[source]¶
Display a numbered list of history items with a count value contained in the inclusive interval
start-end.
- property size¶
The maximum number of entries retained in the preent object.
- property timer¶
Add a timestamp when showing history entries.
- property upper_bound¶
The number of latest history entry in the object