storing force curves.
"""
+from copy_reg import dispatch_table
+from copy import _reconstruct, _copy_dispatch
import logging
import os.path
arguments:
curve: *id001
command: curve info
+ explicit_user_call: true
name: path
path: some/path
<BLANKLINE>
name: path
path: some/path
command: curve info
+ explicit_user_call: true
<BLANKLINE>
"""
def __init__(self, path, info=None):
if type(self.command_stack) == list:
self.command_stack = CommandStack()
+ def __copy__(self):
+ """Set copy to preserve :attr:`_hooke`.
+
+ :meth:`getstate` drops :attr:`_hooke` for :mod:`pickle` and
+ :mod:`yaml` output, but it should be preserved (but not
+ duplicated) during copies.
+
+ >>> import copy
+ >>> class Hooke (object):
+ ... pass
+ >>> h = Hooke()
+ >>> c = Curve(None)
+ >>> c.set_hooke(h)
+ >>> c._hooke # doctest: +ELLIPSIS
+ <hooke.curve.Hooke object at 0x...>
+ >>> c._hooke == h
+ True
+ >>> c2 = copy.copy(c)
+ >>> c2._hooke # doctest: +ELLIPSIS
+ <hooke.curve.Hooke object at 0x...>
+ >>> c2._hooke == h
+ True
+ """
+ copier = _copy_dispatch.get(type(self))
+ if copier:
+ return copier(self)
+ reductor = dispatch_table.get(type(self))
+ if reductor:
+ rv = reductor(self)
+ else:
+ # :class:`object` implements __reduce_ex__, see :pep:`307`.
+ rv = self.__reduce_ex__(2)
+ y = _reconstruct(self, rv, 0)
+ y.set_hooke(self._hooke)
+ return y
+
+ def __deepcopy__(self, memo):
+ """Set deepcopy to preserve :attr:`_hooke`.
+
+ :meth:`getstate` drops :attr:`_hooke` for :mod:`pickle` and
+ :mod:`yaml` output, but it should be preserved (but not
+ duplicated) during copies.
+
+ >>> import copy
+ >>> class Hooke (object):
+ ... pass
+ >>> h = Hooke()
+ >>> c = Curve(None)
+ >>> c.set_hooke(h)
+ >>> c._hooke # doctest: +ELLIPSIS
+ <hooke.curve.Hooke object at 0x...>
+ >>> c._hooke == h
+ True
+ >>> c2 = copy.deepcopy(c)
+ >>> c2._hooke # doctest: +ELLIPSIS
+ <hooke.curve.Hooke object at 0x...>
+ >>> c2._hooke == h
+ True
+ """
+ reductor = dispatch_table.get(type(self))
+ if reductor:
+ rv = reductor(self)
+ else:
+ # :class:`object` implements __reduce_ex__, see :pep:`307`.
+ rv = self.__reduce_ex__(2)
+ y = _reconstruct(self, rv, 1, memo)
+ y.set_hooke(self._hooke)
+ return y
+
def set_hooke(self, hooke=None):
if hooke != None:
self._hooke = hooke