/usr/lib/python2.7/dist-packages/tables/undoredo.py is in python-tables 3.2.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | # -*- coding: utf-8 -*-
########################################################################
#
# License: BSD
# Created: February 15, 2005
# Author: Ivan Vilata - reverse:net.selidor@ivan
#
# $Source$
# $Id$
#
########################################################################
"""Support for undoing and redoing actions.
Functions:
* undo(file, operation, *args)
* redo(file, operation, *args)
* move_to_shadow(file, path)
* move_from_shadow(file, path)
* attr_to_shadow(file, path, name)
* attr_from_shadow(file, path, name)
Misc variables:
`__docformat__`
The format of documentation strings in this module.
"""
from tables.path import split_path
from tables._past import previous_api
__docformat__ = 'reStructuredText'
"""The format of documentation strings in this module."""
def undo(file_, operation, *args):
if operation == 'CREATE':
undo_create(file_, args[0])
elif operation == 'REMOVE':
undo_remove(file_, args[0])
elif operation == 'MOVE':
undo_move(file_, args[0], args[1])
elif operation == 'ADDATTR':
undo_add_attr(file_, args[0], args[1])
elif operation == 'DELATTR':
undo_del_attr(file_, args[0], args[1])
else:
raise NotImplementedError("the requested unknown operation %r can "
"not be undone; please report this to the "
"authors" % operation)
def redo(file_, operation, *args):
if operation == 'CREATE':
redo_create(file_, args[0])
elif operation == 'REMOVE':
redo_remove(file_, args[0])
elif operation == 'MOVE':
redo_move(file_, args[0], args[1])
elif operation == 'ADDATTR':
redo_add_attr(file_, args[0], args[1])
elif operation == 'DELATTR':
redo_del_attr(file_, args[0], args[1])
else:
raise NotImplementedError("the requested unknown operation %r can "
"not be redone; please report this to the "
"authors" % operation)
def move_to_shadow(file_, path):
node = file_._get_node(path)
(shparent, shname) = file_._shadow_name()
node._g_move(shparent, shname)
moveToShadow = previous_api(move_to_shadow)
def move_from_shadow(file_, path):
(shparent, shname) = file_._shadow_name()
node = shparent._f_get_child(shname)
(pname, name) = split_path(path)
parent = file_._get_node(pname)
node._g_move(parent, name)
moveFromShadow = previous_api(move_from_shadow)
def undo_create(file_, path):
move_to_shadow(file_, path)
undoCreate = previous_api(undo_create)
def redo_create(file_, path):
move_from_shadow(file_, path)
redoCreate = previous_api(redo_create)
def undo_remove(file_, path):
move_from_shadow(file_, path)
undoRemove = previous_api(undo_remove)
def redo_remove(file_, path):
move_to_shadow(file_, path)
redoRemove = previous_api(redo_remove)
def undo_move(file_, origpath, destpath):
(origpname, origname) = split_path(origpath)
node = file_._get_node(destpath)
origparent = file_._get_node(origpname)
node._g_move(origparent, origname)
undoMove = previous_api(undo_move)
def redo_move(file_, origpath, destpath):
(destpname, destname) = split_path(destpath)
node = file_._get_node(origpath)
destparent = file_._get_node(destpname)
node._g_move(destparent, destname)
redoMove = previous_api(redo_move)
def attr_to_shadow(file_, path, name):
node = file_._get_node(path)
attrs = node._v_attrs
value = getattr(attrs, name)
(shparent, shname) = file_._shadow_name()
shattrs = shparent._v_attrs
# Set the attribute only if it has not been kept in the shadow.
# This avoids re-pickling complex attributes on REDO.
if not shname in shattrs:
shattrs._g__setattr(shname, value)
attrs._g__delattr(name)
attrToShadow = previous_api(attr_to_shadow)
def attr_from_shadow(file_, path, name):
(shparent, shname) = file_._shadow_name()
shattrs = shparent._v_attrs
value = getattr(shattrs, shname)
node = file_._get_node(path)
node._v_attrs._g__setattr(name, value)
# Keeping the attribute in the shadow allows reusing it on Undo/Redo.
# shattrs._g__delattr(shname)
attrFromShadow = previous_api(attr_from_shadow)
def undo_add_attr(file_, path, name):
attr_to_shadow(file_, path, name)
undoAddAttr = previous_api(undo_add_attr)
def redo_add_attr(file_, path, name):
attr_from_shadow(file_, path, name)
redoAddAttr = previous_api(redo_add_attr)
def undo_del_attr(file_, path, name):
attr_from_shadow(file_, path, name)
undoDelAttr = previous_api(undo_del_attr)
def redo_del_attr(file_, path, name):
attr_to_shadow(file_, path, name)
redoDelAttr = previous_api(redo_del_attr)
## Local Variables:
## mode: python
## py-indent-offset: 4
## tab-width: 4
## End:
|