[Twisted-Python] persistence interface

Sean Riley sean at twistedmatrix.com
Sun Sep 15 13:59:08 EDT 2002

Glyph and I talked about persistence interface for use in twisted.enterprise
initially but with possibly broader implications:

class IPersistence(Interface):

	"""I can generate data to persist my current
	state. The persistent data must be composed of
	basic types that can be handled by common data
	storage systems (relational data bases, XML, etc).
	The data returned shouldn't contain other complex
	python objects, lists or dictionaries.

	def getStateToPersist(self):
		"""Return a dictionary of my persistent data

This could just return self.__dict__ or use a simple implementation like:

class RowObject(IPersistence):
    def getStateToPersist(self):
        kw = {}
        for columnName in self.rowColumns:
            kw[columnName] = getattr(self, columnName)
	  return kw

interesting that this looks a little like "getStateToCopy" in
twisted.spread.pb... Maybe there is some crossover between state persisted
to databases in enterprise and across networks with pb... maybe they could
use the same persistence interface?

"If he's so smart, then how come he's dead?", Homer Simspon
Sean Riley
sean at ninjaneering.com

More information about the Twisted-Python mailing list