Back to index

plone3  3.1.7
data.py
Go to the documentation of this file.
00001 from Products.PortalTransforms.interfaces import idatastream
00002 
00003 class datastream:
00004     """A transformation datastream packet"""
00005     __implements__ = idatastream
00006     __slots__ = ('name', '_data', '_metadata')
00007 
00008     def __init__(self, name):
00009         self.__name__ = name
00010         self._data = ''
00011         self._metadata = {}
00012         self._objects = {}
00013         self._cacheable = 1
00014 
00015     def __str__(self):
00016         return self.getData()
00017 
00018     def name(self):
00019         return self.__name__
00020 
00021     def setData(self, value):
00022         """set the main data produced by a transform, i.e. usually a string"""
00023         self._data = value
00024 
00025     def getData(self):
00026         """provide access to the transformed data object, i.e. usually a string.
00027         This data may references subobjects.
00028         """
00029         if callable(self._data):
00030             data = self._data()
00031         else:
00032             data = self._data
00033         return data
00034 
00035     def setSubObjects(self, objects):
00036         """set a dict-like object containing subobjects.
00037         keys should be object's identifier (e.g. usually a filename) and
00038         values object's content.
00039         """
00040         self._objects = objects
00041 
00042     def getSubObjects(self):
00043         """return a dict-like object with any optional subobjects associated
00044         with the data"""
00045         return self._objects
00046 
00047     def getMetadata(self):
00048         """return a dict-like object with any optional metadata from
00049         the transform"""
00050         return self._metadata
00051     
00052     def isCacheable(self):
00053         """Return a bool which indicates wether the result should be cached
00054         
00055         Default is true
00056         """
00057         return self._cacheable
00058     
00059     def setCacheable(self, value):
00060         """Set cacheable flag to yes or no
00061         """
00062         self._cacheable = not not value
00063 
00064     #data = property('getData', 'setData', None, """idata.data""")
00065 
00066     #metadata = property('getMetadata', 'setMetadata', None,
00067     #"""idata.metadata""")