Re: [ZODB-Dev] How can I append Persistent mechanism to OrderedDict class ?
Le 30/01/2011 12:12, Vincent Pelletier a écrit : Le dimanche 30 janvier 2011 09:52:32, Stéphane Klein a écrit : How can I append Persistent mechanism to this OrderedDict class ? You should probably read the code for PersistentMapping[1] and adapt it to OrderedDict's API. [1] http://svn.zope.org/ZODB/trunk/src/persistent/mapping.py?rev=113734view=markup Hi, I'll try that : from collections import OrderedDict from persistent import Persistent class PersistentOrderedDict(OrderedDict, Persistent): pass but I've this error : TypeError: Error when calling the metaclass bases multiple bases have instance lay-out conflict Then, I can't do like persistent.mapping.PersistentMapping class PersistentMapping(UserDict.IterableUserDict, persistent.Persistent) I need to create PersistentOrderedDict that need to be a proxy class over OrderedDict, and a child on Persistent ? Regards, Stephane -- Stéphane Klein steph...@harobed.org blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com ___ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org https://mail.zope.org/mailman/listinfo/zodb-dev
Re: [ZODB-Dev] How can I append Persistent mechanism to OrderedDict class ?
Le 16/09/2011 10:07, Stéphane Klein a écrit : Le 30/01/2011 12:12, Vincent Pelletier a écrit : Le dimanche 30 janvier 2011 09:52:32, Stéphane Klein a écrit : How can I append Persistent mechanism to this OrderedDict class ? You should probably read the code for PersistentMapping[1] and adapt it to OrderedDict's API. [1] http://svn.zope.org/ZODB/trunk/src/persistent/mapping.py?rev=113734view=markup Hi, I'll try that : from collections import OrderedDict from persistent import Persistent class PersistentOrderedDict(OrderedDict, Persistent): pass but I've this error : TypeError: Error when calling the metaclass bases multiple bases have instance lay-out conflict Then, I can't do like persistent.mapping.PersistentMapping class PersistentMapping(UserDict.IterableUserDict, persistent.Persistent) I need to create PersistentOrderedDict that need to be a proxy class over OrderedDict, and a child on Persistent ? I've just created this class, what do you about ? from collections import OrderedDict from persistent import Persistent class PersistentOrderedDict(Persistent): def __init__(self, *args, **kwds): self.__data = OrderedDict(*args, **kwds) def __setitem__(self, key, value, PREV=0, NEXT=1, dict_setitem=dict.__setitem__): res = self.__data.__setitem__(key, value, PREV=0, NEXT=1, dict_setitem=dict.__setitem__) self._p_changed = 1 return res def __delitem__(self, key, PREV=0, NEXT=1, dict_delitem=dict.__delitem__): res = self.__data.__delitem__(key, PREV=0, NEXT=1, dict_delitem=dict.__delitem__) self._p_changed = 1 return res def __iter__(self, NEXT=1, KEY=2): return self.__data.__iter__(NEXT=1, KEY=2) def __reversed__(self, PREV=0, KEY=2): return self.__data.__reversed__(PREV=0, KEY=2) def __reduce__(self): return self.__data.__reduce__() def clear(self): return self.__data.clear() def setdefault(self, key, default=None): if key in self.__data: return self.__data[key] self.__data[key] = default self._p_changed = 1 return default def update(self, other): res = self.__data.update(other) self._p_changed = 1 return res def pop(self, key, default=None): res = self.__data.pop(key, default) self._p_changed = 1 return res def keys(self): return self.__data.keys() def values(self): return self.__data.values() def items(self): return self.__data.items() def iterkeys(self): return self.__data.iterkeys() def itervalues(self): return self.__data.itervalues() def iteritems(self): return self.__data.iteritems() def __ne__(self, other): return self.__ne__(other) def viewkeys(self): return self.__data.viewkeys() def viewvalues(self): return self.__data.viewvalues() def viewitems(self): return self.__data.viewitems() def popitem(self, last=True): return self.__data.popitem(last=last) def __repr__(self): return self.__data.__repr__() def copy(self): return self.__data.copy() @classmethod def fromkeys(cls, iterable, value=None): return OrderedDict.fromkeys(iterable, value) def __eq__(self, other): return self.__data.__eq__(other) -- Stéphane Klein steph...@harobed.org blog: http://stephane-klein.info Twitter: http://twitter.com/klein_stephane pro: http://www.is-webdesign.com ___ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org https://mail.zope.org/mailman/listinfo/zodb-dev
Re: [ZODB-Dev] How can I append Persistent mechanism to OrderedDict class ?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Stéphane Klein schrieb: Hi, I would like to use a Persistent Ordered dict. I use OrderedDict (http://pypi.python.org/pypi/ordereddict). How can I append Persistent mechanism to this OrderedDict class ? What is the particular problem? As look as a Python object can be pickled it can be persisted within the ZODB. The only issue you will encounter that you have to notify the container object the _p_changed variable upon changes (see http://www.zodb.org/). - -aj -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQGUBAEBAgAGBQJNRUXIAAoJEADcfz7u4AZjnyILwOJUkYxdxhEad49TRfI4BuZ5 cqfndCiNs1w4sAbXyrCsrgiSVPH6P0CgnsspLVjOUXJ0tXAmtem48SWVx0FHiIl7 21bG3IRYD5R4SCPxyCVNTneRjgQpsSc4MRJ0qWaGEjZwtu/NikB/su0hb/QepYiJ Ok86/ipI7sgi9z6qDgFbePP2Z3tVcK8/djkj8QGnOimFR+ccX2qF/JBevSPFZByD DL5IcDbBLeKEohTsD/Q1v9b14iQTs5sHab3CyHOE4Vnhn7ZLNu2VyyMbnvJz+A12 j0NiRjd7bhdj/Xsn0lNuPnR5cdUFiabYAkFW4zkDfsjO5One75/60ckS+3yOWkf1 CQ26e7/75wdi7OFPX8QjjWJ49g5ipt4m79Amti8pFibTNURO0CUKBRWjNjGPVNBT 4JDiqdjpu3juj5wykqrhm7x9G5+fUfl9TG7Gx5bEB14xTGgEvvHrWoM18dZq9In2 TkAtS8hO6Pan4DJI6s0xgYrPVPNjbgw= =Dkd4 -END PGP SIGNATURE- attachment: lists.vcf___ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org https://mail.zope.org/mailman/listinfo/zodb-dev
Re: [ZODB-Dev] How can I append Persistent mechanism to OrderedDict class ?
Le dimanche 30 janvier 2011 09:52:32, Stéphane Klein a écrit : How can I append Persistent mechanism to this OrderedDict class ? You should probably read the code for PersistentMapping[1] and adapt it to OrderedDict's API. [1] http://svn.zope.org/ZODB/trunk/src/persistent/mapping.py?rev=113734view=markup -- Vincent Pelletier ___ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org https://mail.zope.org/mailman/listinfo/zodb-dev