Re: Re: extending PersistentList
Lars van Gemerden <[email protected]>
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <[email protected]> |
I am storing the list items in self.items. Sequence and its subclass MutableSequence is designed in such a way that by implementing the abstract methods (the methods implemented in PersistentList2), all other standard list methods (like extend, slicing, etc.) follow suit. They basically all call the overridden abstract methods to do the actual item lookup or list mutations. By just overriding these couple of method, e.g. calling extend will also set _p_changed to 1. The original PersistentList is a subclass of UserList, which is a subclass of MutableSequence as well, but then overrides all methods of MutableSequence, which makes the inheritance pointless. It probably is a little faster though because it less method calls are used. Another disadvantage of this is that if you want to override PersistentList, you likely will have to override or extend all methods, which is error prone, and more code to maintain. self.owner.__dirty__ = True is a way for me to keep track of changed objects (setting the containing object's __dirty__ to True in a descriptor), for syncing between web clients and server (it needs work though, i am learning somethings from zodb as well ;-). The idea is to use classes in a python client that are (only) defined on the server. Anyway, thnaks for the feedback. May i conclude that,apart from the MutableSequence stuff, PersistentList2 should work with zodb persistence? Cheers, Lars On Sunday, May 8, 2016 at 1:37:37 PM UTC+2, Christopher Lozinski wrote: > > At first it all looked too easy. > > PersistentList stores the objects in itself, and is complex. It is indeed easier to create > PersistentList2 by pointing to a List object and updating _p_changed. > > So I will assume that you are storing your objects in the attached list, and not in the > PersistentList2 itself. > > But then you do not need to subclass off of MutableSequence. Worse yet, if > you do subclass off of > MutableSequence, but only implement some of the methods, for example no > slice methods, if you ever use the slice method, it will execute on the > object itself, and not on the linked to list. > > Here are some other comments. > > It was a great idea to separate out your application code ServerField List > from PersistentList2. > > Makes it much easier for us to understand what you are doing, and the > relevance to everyone else. > > You did not say what is wrong with Persistent List. What is it that you > are trying to add. Maybe someone else > > has already done it? > > What is that > > self.owner.__dirty__ = True > all about? > Hope that helps. > Chris > > -- You received this message because you are subscribed to the Google Groups "zodb" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.