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.
- 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
Persistentsubclass, as that rather defeats the point (but it is still allowed for backwards compatibility).
- class PersistentExternalizableDictionary[source]
Bases:
dict,ExternalizableDictionaryMixinDictionary 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(iterable=(), /)[source]
Bases:
listList 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:
PersistentExternalizableListStores
persistent.Persistentobjects 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(item, *args)[source]
Return first index of value.
Raises ValueError if the value is not present.
- getPersistentState(obj)[source]
For a
persistent.Persistentobject, returns one of the constants from the persistent module for its state:persistent.CHANGEDandpersistent.UPTODATEbeing the most useful.If the object is not Persistent and doesn’t implement a
getPersistentStatemethod, this method will be pessimistic and assume the object has beenpersistent.CHANGED.