Oh no, it works exactly as i expect.  I was just wondering because I
was changing the implementation and did not want to change the
behavior. Well no changes other than to call the specialized version
of .elements(...)

Here is the change I have added so far:
    def elements(self, *args, **kargs):
        """
        find all component that match the supplied attribute
dictionary,
        or None if nothing could be found

        All components of the components are searched.
        """
        # make a copy of the components
        matches = []
        first_only = False
        if kargs.has_key("first_only"):
            first_only = kargs["first_only"]
            del kargs["first_only"]
        try:
            # check if the component has an attribute with the same
            # value as provided
            check = True
            tag = getattr(self,'tag').replace("/","")
            if args and tag not in args:
                    check = False
            for (key, value) in kargs.items():
                if self[key] != value:
                    check = False
            # if found, return the component
            if check:
                matches.append(self)
                if first_only:
                    return matches
        except:
            pass
        # loop the copy
        for c in self.components:
            if isinstance(c, XmlComponent):
                kargs['first_only'] = first_only
                child_matches = c.elements( *args,  **kargs )
                if first_only  and len(child_matches) != 0:
                    return child_matches
                matches.extend( child_matches )
        return matches

How might I go about getting this considered for web2py?


mdipierro wrote:
> It makes a copy of the list of components (shallowcopy), not a
> deepcopy. that means that it returns a new list but the objects in
> there should still be references to the original helpers and you can
> modify them. Does this cause unexpected behaviour? If so can you post
> an example? Perhaps we can improve it.
>
> On May 19, 1:38 pm, Ian Reinhart Geiser <[email protected]> wrote:
> > Greetings, is there a technical reason why DIV.elements makes a copy
> > of the elements that it returns?  The reason I am asking is because I
> > am making a minor change to it to allow it to call children's
> > elements() method.  This way I can overload the elements() method in
> > those children.  The reason I am doing this is I have some SCRIPT()
> > objects that are being created in the children but only after all of
> > their children have been added.  Then I am using
> > DIV.elements('script') to extract all of these individual scripts and
> > place them as a preceding sibling SCRIPT object to the top level DIV.
> > At any rate, I just want to make sure that there is a good reason that
> > a copy is being performed so I can preserve that when I finish the
> > refactoring.
> >
> > As a side note, from what I can tell is DIV.siblings is the same
> > story, but it doesn't make a copy of the elements it returns.

Reply via email to