Back to index

plone3  3.1.7
interfaces.py
Go to the documentation of this file.
00001 from zope.interface import Interface as z3Interface
00002 from Interface import Interface
00003 
00004 class idatastream(Interface):
00005     """data stream, is the result of a transform"""
00006 
00007     def setData(value):
00008         """set the main data produced by a transform, i.e. usually a string"""
00009 
00010     def getData():
00011         """provide access to the transformed data object, i.e. usually a string.
00012         This data may references subobjects.
00013         """
00014 
00015     def setSubObjects(objects):
00016         """set a dict-like object containing subobjects.
00017         keys should be object's identifier (e.g. usually a filename) and
00018         values object's content.
00019         """
00020 
00021     def getSubObjects():
00022         """return a dict-like object with any optional subobjects associated
00023         with the data"""
00024 
00025     def getMetadata():
00026         """return a dict-like object with any optional metadata from
00027         the transform
00028         You can modify the returned dictionnary to add/change metadata
00029         """
00030         
00031     def isCacheable():
00032         """Return a bool which indicates wether the result should be cached
00033         
00034         Default is true
00035         """
00036         
00037     def setCachable(value):
00038         """Set cacheable flag to yes or no
00039         """
00040 
00041 class itransform(Interface):
00042     """A transformation plugin -- tranform data somehow
00043     must be threadsafe and stateless"""
00044 
00045 #     inputs = Attribute("""list of imimetypes (or registered rfc-2046
00046 #     names) this transform accepts as inputs.""")
00047 
00048 #     output = Attribute("""output imimetype as instance or rfc-2046
00049 #     name""")
00050 
00051 #     output_encoding = Attribute("""output encoding of this transform.
00052 #     If not specified, the transform should output the same encoding as received data
00053 #     """)
00054 
00055     def name(self):
00056         """return the name of the transform instance"""
00057 
00058     def convert(data, idata, filename=None, **kwargs):
00059         """convert the data, store the result in idata and return that
00060 
00061         optional argument filename may give the original file name of received data
00062 
00063         additional arguments given to engine's convert, convertTo or __call__ are
00064         passed back to the transform
00065         
00066         The object on which the translation was invoked is available as context
00067         (default: None)
00068         """
00069 
00070 
00071 class ichain(itransform):
00072 
00073     def registerTransform(transform, condition=None):
00074         """Append a transform to the chain"""
00075 
00076 
00077 class iengine(Interface):
00078 
00079     def registerTransform(transform):
00080         """register a transform
00081 
00082         transform must implements itransform
00083         """
00084 
00085     def unregisterTransform(name):
00086         """ unregister a transform
00087         name is the name of a registered transform
00088         """
00089 
00090     def convertTo(mimetype, orig, data=None, object=None, context=None, **kwargs):
00091         """Convert orig to a given mimetype
00092 
00093         * orig is an encoded string
00094 
00095         * data an optional idatastream object. If None a new datastream will be
00096         created and returned
00097 
00098         * optional object argument is the object on which is bound the data.
00099         If present that object will be used by the engine to bound cached data.
00100         
00101         * optional context argument is the object on which the transformation
00102           was called.
00103 
00104         * additional arguments (kwargs) will be passed to the transformations.
00105 
00106         return an object implementing idatastream or None if no path has been
00107         found.
00108         """
00109 
00110     def convert(name, orig, data=None, context=None, **kwargs):
00111         """run a tranform of a given name on data
00112 
00113         * name is the name of a registered transform
00114 
00115         see convertTo docstring for more info
00116         """
00117 
00118     def __call__(name, orig, data=None, context=None, **kwargs):
00119         """run a transform by its name, returning the raw data product
00120 
00121         * name is the name of a registered transform.
00122 
00123         return an encoded string.
00124         see convert docstring for more info on additional arguments.
00125         """
00126 
00127 class IPortalTransformsTool(z3Interface):
00128     """Marker interface for the portal_transforms tool."""