[Zope-dev] making a deepcopy of an ExtensionClass instance?

Toby Sargeant toby@inpharmatica.co.uk
Wed, 22 Nov 2000 16:11:53 +0000


The only way I've found to do this thus far is to add the following method to
classes which I want to have deepcopyable instances:

   def __deepcopy__(self,memo):
      self=getattr(self,'aq_base',self)
      new=cPickle.loads(cPickle.dumps(self))
      new.__dict__=copy.deepcopy(self.__dict__,memo)
      return new

using cPickle like that seems really slow and ugly, and requiring that every
class that might be deepcopied at the very least inherits from a mixin is
less than optimal.

Does anyone have a better solution?

Thanks,

Toby.

-- 
  [ Toby Sargeant : Inpharmatica : Developer : t.sargeant@inpharmatica.co.uk ]
      [ http://www.inpharmatica.co.uk : 020 7631 4644 fax 020 7631 4844 ]