[Zope] Copying objects

Jesper Holmberg jesper.holmberg@enst-bretagne.fr
Sat, 17 Nov 2001 00:20:48 +0100


Hi all,

I have a problem that's driving me crazy. Hopefully someone here can help
me sort it out.

I have two products, Itinerary and Step. They are both subclasses of
"Folder". I am parsing an XML-file into a DOM, using the xml.dom.minidom.
The resulting DOM object is an attribute of an Itinerary instance.
With the help of this DOM, I then create a hierarchy of the Itinerary and
several Steps.

For each DOM-element of type "Step", I create a Step in Zope. Each Step
has as an attribute the node in the DOM to which it is associated. So, in
the Itinerary code, I have something like this:

for childNode in self.dom.childNodes:
    if childNode.tagName == "Step":
        id = 'step_%d' % len(self.objectIds())
        manage_addStep(self, id, childNode)

So far, so good. I get a hierarchy of Steps that expresses my DOM. But
here my troubles begin. I want to add objects of type Link to the
Itinerary folders, and to the Step folders. These changes should be
reflected in changes in the DOM.

So I have this method:

def manage_addLinkAction(self, id, node=None, REQUEST=None):
    "Add a Link to a folder."
              ...
	      
    self._setObject(id, Link(id, node))
    linkNode = minidom.Element("Link")
    self.node.appendChild(linkNode)

This does not give any errors. BUT: if a Link is added directly to an
Itinerary, the change is reflected in the DOM, but this does not work if I
add a Link to a Step.

It thus seems to me that the Step actually has a copy of the node it
was given as parameter when it was created, and not the original node
itself. Since it's only the copy that is being manipulated by the adding
of nodes, the original DOM which rests in the Itinerary object is not
affected.

I don't understand why this is so. It doesn't fit with how I had
understood the treatment of objects as parameters in Python. Could someone
please help me sort this out.

If I have not given enough information, I'd be happy to supply it.

TIA,

Jesper


-- 
          Jesper Holmberg            |"But how can |
  jesper.holmberg@enst-bretagne.fr   | one be warm |
ENST Br, BP 832, 29285 Brest, FRANCE | alone?"     |