You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
903 B
34 lines
903 B
empty_doc = __new__(DOMParser()).parseFromString("<empty />", "text/xml")
|
|
|
|
|
|
class Editable:
|
|
def make_copy(self):
|
|
# makes an internal copy of self
|
|
# delete old copy
|
|
if hasattr(self, "_copy"):
|
|
if self._copy is not None:
|
|
self._copy = None
|
|
|
|
# make new copy
|
|
self._copy = JSON.parse(JSON.stringify(self))
|
|
|
|
def copy(self):
|
|
# return internal copy of self
|
|
# check if even initialized
|
|
if hasattr(self, "_copy"):
|
|
return self._copy
|
|
else:
|
|
return None
|
|
|
|
def overwrite_with_copy(self):
|
|
for key, value in dict(self._copy).items():
|
|
if key == "_copy":
|
|
continue
|
|
setattr(self, key, value)
|
|
|
|
self._copy = None
|
|
|
|
@classmethod
|
|
def new_empty(cls):
|
|
return cls(empty_doc)
|