nti.externalization.persistence
: Pickling and ZODB support¶
Classes and functions for dealing with persistence (and pickling) in an external context.
Note
Importing this module monkey-patches the class persistent.wref.WeakRef
to directly implement toExternalObject()
and toExternalOID()
.
It’s not clear why we don’t simply register class adapters for those things,
but we don’t.
-
getPersistentState
(obj)[source]¶ For a
persistent.Persistent
object, returns one of the constants from the persistent module for its state:persistent.CHANGED
andpersistent.UPTODATE
being the most useful.If the object is not Persistent and doesn’t implement a
getPersistentState
method, this method will be pessimistic and assume the object has beenpersistent.CHANGED
.
-
class
PersistentExternalizableDictionary
(**kwargs)[source]¶ Bases:
persistent.mapping.PersistentMapping
,nti.externalization.datastructures.ExternalizableDictionaryMixin
Dictionary mixin that provides
toExternalDictionary()
to return a new dictionary with each value in the dict having been externalized withtoExternalObject()
.Changed in version 1.0: No longer extends
nti.zodb.persistentproperty.PersistentPropertyHolder
. If you have subclasses that use writable properties and which should bypass the normal attribute setter implementation, please mixin this superclass (first) yourself.
-
class
PersistentExternalizableList
(initlist=None)[source]¶ Bases:
persistent.list.PersistentList
List mixin that provides
toExternalList()
to return a new list with each element in the sequence having been externalized withtoExternalObject()
.Changed in version 1.0: No longer extends
nti.zodb.persistentproperty.PersistentPropertyHolder
. If you have subclasses that use writable properties and which should bypass the normal attribute setter implementation, please mixin this superclass (first) yourself.
-
class
PersistentExternalizableWeakList
(initlist=None)[source]¶ Bases:
nti.externalization.persistence.PersistentExternalizableList
Stores
persistent.Persistent
objects as weak references, invisibly to the user. Any weak references added to the list will be treated the same.Weak references are resolved on access; if the referrant has been deleted, then that access will return
None
.Changed in version 1.0: No longer extends
nti.zodb.persistentproperty.PersistentPropertyHolder
. If you have subclasses that use writable properties and which should bypass the normal attribute setter implementation, please mixin this superclass (first) yourself.-
index
(value) → integer -- return first index of value.[source]¶ Raises ValueError if the value is not present.
-
-
NoPickle
(cls)[source]¶ A class decorator that prevents an object from being pickled. Useful for ensuring certain objects do not get pickled and thus avoiding ZODB backward compatibility concerns.
Warning
Subclasses of such decorated classes are also not capable of being pickled, without appropriate overrides of
__reduce_ex__
and__getstate__
. A “working” subclass, but only for ZODB, looks like this:@NoPickle class Root(object): pass class CanPickle(Persistent, Root): pass
Warning
This decorator emits a warning when it is used directly on a
Persistent
subclass, as that rather defeats the point (but it is still allowed for backwards compatibility).