Re: extending PersistentList
Lars van Gemerden <[email protected]>
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I have made an alternative PersistenList, but would like to know if this
could cause me trouble later on.
class PersistenList2(MutableSequence, Persistent):
def __init__(self, items, owner=None):
self.items = list(items)
def __len__(self):
return len(self.items)
def __getitem__(self, index):
return self.items[index]
def __setitem__(self, index, value):
self.items[index] = value
self._p_changed = True
def __delitem__(self, index):
del self.items[index]
self._p_changed = True
def insert(self, index, value):
self.items.insert(index, value)
self._p_changed = True
def __eq__(self, other):
if isinstance(other, PersisitenList2):
return self.items == other.items
return self.items == other
def __ne__(self, other):
return not (self == other)
I have stripped out the code needed for my own project (the __dirty__ lines below, ehm). My main question is whether this will persist correctly and if there are any disadvantages compared to the standard PersistentList.
Cheers, Lars
On Friday, May 6, 2016 at 10:21:09 PM UTC+2, Lars van Gemerden wrote:
>
> Hi,
>
> I have been looking for a way to extend PersistentList in an elegant way.
> I tried overriding the abstract methods in MutableSequence but ofcourds
> that does not work, because UserList overrides all methods in
> MutableSequence (don't know why; speed reasons?).
>
> I also tried this:
>
> class ServerFieldList(PersistentList):
>
> def __init__(self, items, owner=None):
> super(ServerFieldList, self).__init__(items)
> self.owner = owner
>
> def _get_changed(self):
> return Persistent._get_changed(self)
>
> def _set_changed(self, value):
> Persistent._set_changed(self, value)
> self.owner.__dirty__ = True
>
> def _del_changed(self):
> Persistent._del_changed(self)
> self.owner.__dirty__ = True
>
> _p_changed = property(_get_changed, _set_changed, _del_changed)
>
>
>
> but directly both calling the _get_changed etc methods in Persistent or using super(ServerFieldList, self) gives me an AttributeError, while i can clearly see these methods in Persistent. must have something to do with the @implementer decorator.
>
>
> Is there anyway to access the _get_changed directly, or any way to get this to work, preferably without extending all methods in PersistentList or UserList?
>
>
> Cheers, Lars
>
>
--
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.