MCPcopy Index your code
hub / github.com/PyTables/PyTables / undo

Method undo

tables/file.py:2723–2766  ·  view source on GitHub ↗

Go to a past state of the database. Returns the database to the state associated with the specified mark. Both the identifier of a mark and its name can be used. If the mark is omitted, the last created mark is used. If there are no past marks, or the specified mark

(self, mark: int | str | None = None)

Source from the content-addressed store, hash-verified

2721 self._curaction += direction
2722
2723 def undo(self, mark: int | str | None = None) -> None:
2724 """Go to a past state of the database.
2725
2726 Returns the database to the state associated with the specified mark.
2727 Both the identifier of a mark and its name can be used. If the mark is
2728 omitted, the last created mark is used. If there are no past
2729 marks, or the specified mark is not older than the current one, an
2730 UndoRedoError is raised.
2731
2732 This method can only be called when the Undo/Redo mechanism
2733 has been enabled. Otherwise, an UndoRedoError
2734 is raised.
2735
2736 """
2737 self._check_open()
2738 self._check_undo_enabled()
2739
2740 # print("(pre)UNDO: (curaction, curmark) = (%s,%s)" % \
2741 # (self._curaction, self._curmark))
2742 if mark is None:
2743 markid = self._curmark
2744 # Correction if we are settled on top of a mark
2745 opcode = self._actionlog.cols.opcode
2746 if opcode[self._curaction] == _op_to_code["MARK"]:
2747 markid -= 1
2748 else:
2749 # Get the mark ID number
2750 markid = self._get_mark_id(mark)
2751 # Get the final action ID to go
2752 finalaction = self._get_final_action(markid)
2753 if finalaction > self._curaction:
2754 raise UndoRedoError(
2755 "Mark ``%s`` is newer than the current mark. "
2756 "Use `redo()` or `goto()` instead." % (mark,)
2757 )
2758
2759 # The file is going to be changed.
2760 self._check_writable()
2761
2762 # Try to reach this mark by unwinding actions in the log
2763 self._doundo(finalaction - 1, -1)
2764 if self._curaction < self._actionlog.nrows - 1:
2765 self._curaction += 1
2766 self._curmark = int(self._actionlog.cols.arg1[self._curaction])
2767
2768 # print("(post)UNDO: (curaction, curmark) = (%s,%s)" % \
2769 # (self._curaction, self._curmark))

Callers 15

gotoMethod · 0.95
_doundoMethod · 0.80
test00_simpleMethod · 0.80
test01_twiceMethod · 0.80
test02_twice2Method · 0.80
test03_6times3marksMethod · 0.80
test04_6times3marksroMethod · 0.80
test05_destructiveMethod · 0.80
test05b_destructiveMethod · 0.80
test05c_destructiveMethod · 0.80
test05d_destructiveMethod · 0.80
test05e_destructiveMethod · 0.80

Calls 7

_check_openMethod · 0.95
_check_undo_enabledMethod · 0.95
_get_mark_idMethod · 0.95
_get_final_actionMethod · 0.95
_check_writableMethod · 0.95
_doundoMethod · 0.95
UndoRedoErrorClass · 0.85

Tested by 15

test00_simpleMethod · 0.64
test01_twiceMethod · 0.64
test02_twice2Method · 0.64
test03_6times3marksMethod · 0.64
test04_6times3marksroMethod · 0.64
test05_destructiveMethod · 0.64
test05b_destructiveMethod · 0.64
test05c_destructiveMethod · 0.64
test05d_destructiveMethod · 0.64
test05e_destructiveMethod · 0.64
test05f_destructiveMethod · 0.64
test06_totalunwindMethod · 0.64