Memento API Documentation
- class Memento(state)[source]
Bases:
objectStores the state of the Originator.
- Parameters:
state (str)
- class Originator[source]
Bases:
objectCreates and restores Mementos to manage its state.
- set_state(state)[source]
Sets the state of the Originator.
- Parameters:
state (
str) – The new state.
- get_state()[source]
Gets the current state of the Originator.
- Return type:
- Returns:
The current state.
- class Caretaker[source]
Bases:
objectManages Mementos to track the history of the Originator’s states.
- add_memento(memento)[source]
Adds a Memento to the history.
- Parameters:
memento (
Memento) – The Memento to add.
- get_memento(index)[source]
Retrieves a Memento by index.
- Parameters:
index (
int) – The index of the desired Memento.- Return type:
- Returns:
The Memento at the specified index.
- Raises:
IndexError – If the index is out of bounds.