+ 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
+