[Zope-dev] Making copies of ExtensionClass instances

Greg Ward gward@mems-exchange.org
Fri, 15 Sep 2000 12:32:52 -0400


Hi all --

I don't imagine I'm the first one to have this problem, but I don't see
anything obvious in either the source or docs for ExtensionClass that
helps: how do you make a copy of an ExtensionClass instance?  The 'copy'
module can't handle it, because it dispatches on type, and 1) it doesn't
know about the type ExtensionClass, and 2) the type of an extension
class instances is its extension class, so I can't just add an entry to
the 'copy' module's dispatch table.

So I tried to write my own 'copy()' method... but that foundered when I
couldn't find a way to create a new instance of a particular extension
class without using its constructor.  The 'new' module can't do it, as
it's 'instance()' function doesn't know about extension classes either.
Argh!

So what's the trick?  Surely pickle and cPickle have a way to create new
extension class instances when unpickling -- copying is pretty close to
pickle/unpickle, so how I do it?

Thanks --

        Greg