1 from copy import deepcopy
5 """
6 Memento class as part of the Memento design pattern.
7
8 - External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Behavioral-Pattern-Usage}
9 - External Memento Pattern documentation: U{https://en.wikipedia.org/wiki/Memento_pattern}
10 """
12 """
13 Initialize a new Memento instance.
14
15 @param state: The state to save in this Memento.
16 @type state: dict
17 """
18 self.__state = state
19
20 @property
23
26 """
27 Originator base class as part of the Memento design pattern.
28
29 - External Usage documentation: U{https://github.com/tylerlaberge/PyPatterns/wiki/Behavioral-Pattern-Usage}
30 - External Mediator Pattern documentation: U{https://en.wikipedia.org/wiki/Memento_pattern}
31 """
33 """
34 Commit this objects state to a memento.
35
36 @return: A memento instance with this objects state.
37 """
38 return Memento(deepcopy(self.__dict__))
39
41 """
42 Rollback this objects state to a previous state.
43
44 @param memento: The memento object holding the state to rollback to.
45 @type memento: Memento
46 """
47 self.__dict__ = memento.state
48