Trees | Indices | Help |
|
---|
|
I provide functionality for elements with a content. I assume that I will be mixed in subclasses of PackageElement. Note that there are 4 kinds of contents: backend-stored contents: those contents have no URL, and are stored directly in the backend; their data can be modified through this class. external contents: they have a URL at which their data is stored; their data can not be modified through this class. packaged contents: they have a URL in the special ``packaged:`` scheme, meaning that their data is stored in the local filesystem (usually extracted from a zipped package); their data can be modified through this class. empty content: only authorized for relations; they are marked by the special mimetype "x-advene/none"; neither their model, URL nor data can be modified. It follows that content-related properties are not independant from one another. Property `content_mimetype` has higher priority, as it is used to decide whether the content is empty or not (hence whether the other properties can be set or not). Then `content_url` is used to decide between the three other kinds of content, in order to decide whether `content_data` can be set or not. See the documentation of each property for more detail. Content initialization ====================== According to CODING_STYLE, a mixin class should not require any initialization. However, whenever an element is instantiated from backend data, its content information is available, so it would be a waste of CPU time (and possibly network traffic) to reload those info from the backend from the sake of purity. Hence, this class provides a method _instantiate_content, to be used as an optimizationin the instantiate class method of element classes. However, the implementation does not rely on the fact that the mixin will be initialized with this method. Content handler =============== Some element types, like views and queries, require a content handler which depends on their content's mimetype. This mixin provides a hook method, named `_update_content_handler`, which is invoked after the mimetype is modified.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
|
|
|||
|
|||
|
|
|||
__mimetype = None
|
|||
__model_id = None
|
|||
__url = None
|
|||
__data = None
|
|||
__as_synced_file = None
|
|||
__handler = None
|
|
|||
content Return a `Content` instance representing the content. |
|||
content_as_file This property returns a *copy* of this element's content data wrapped in a file-like object. |
|||
content_data This property holds the data of the content. |
|||
content_is_textual This property indicates if this element's content data can be handled as text. |
|||
content_mimetype The mimetype of this element's content. |
|||
content_model The resource used as the model of the content of this element. |
|||
content_model_id The id-ref of the content model, or an empty string. |
|||
content_parsed | |||
content_url This property holds the URL of the content, or an empty string. |
|
This is method is for optimization only: it is not strictly required (though recommended) to call it at instantiate time (see class docstring). No integrity constraint is checked: the backend is assumed to be sane. |
Check that the provided values (assumed to be the future values of the corresponding attributes) are valid and consistent (with each other *and* with unmodified attributes). NB: we do *not* check that model_id identifies a resource. Use _check_reference for that. |
Return the resource used as the model of the content of this element. Return None if that content has no model. If the model can not be retrieved, the default value is returned. See also `content_model` and `content_model_id`. |
Return a file-like object giving access to the content data. The file-like object is updatable unless the content is external. It is an error to try to modify the data while such a file-like object is opened. An exception will thus be raised whenever this method is invoked or `content_data` is set before a previously returned file-like object is closed. See also `content_data`. |
The mimetype of this element's content. If set to "x-advene/none", the other properties are erased and become unsettable. Note that it is only possible for relations.
|
|
This property indicates if this element's content data can be handled as text. It uses the mimetypes registered with `advene.model.content.register.register_textual_mimetype`.
|
The resource used as the model of the content of this element. None if that content has no model. If the model can not be retrieved, an exception is raised. See also `get_content_model` and `content_model_id`.
|
FIXME: missing docstring.
|
The id-ref of the content model, or an empty string. This is a read-only property giving the id-ref of the resource held by `content_model`, or an empty string if there is no model. Note that this property is accessible even if the corresponding model is unreachable. See also `get_content_model` and `content_model`.
|
This property holds the URL of the content, or an empty string. Its value determines whether the content is backend-stored, external or packaged. Note that setting a standard URL (i.e. not in the ``packaged:`` scheme) to a backend-stored or packaged URL will discard its data. On the other hand, changing from backend-store to packaged and vice-versa keeps the data. Finally, note that setting the URL to one in the ``packaged:`` model will automatically create a temporary directory and set the PACKAGED_ROOT metadata of the package to that directory.
|
See `_get_content_url`.
|
This property holds the data of the content. It can be read whatever the kind of content (backend-stored, external or packaged). However, only backend-stored and packaged can have their data safely modified. Trying to set the data of an external content will raise a `ValueError`. Its `content_url` must first be set to the empty string or a ``packaged:`` URL. See also `get_content_as_synced_file`.
|
See `_get_content_data`.
|
|
|
This property returns a *copy* of this element's content data wrapped in a file-like object. Note that the returned file-like object may be writable, but the written data will *not* be reflected back to the content. Also, if the content data is modified between the moment where this method is called and the moment the file-like object is actually read, thoes changes will not be included in the read data. For a synchronized file-like object, see `get_content_as_synced_file`.
|
Return a `Content` instance representing the content.
|
|
contentReturn a `Content` instance representing the content.
|
content_as_fileThis property returns a *copy* of this element's content data wrapped in a file-like object. Note that the returned file-like object may be writable, but the written data will *not* be reflected back to the content. Also, if the content data is modified between the moment where this method is called and the moment the file-like object is actually read, thoes changes will not be included in the read data. For a synchronized file-like object, see `get_content_as_synced_file`.
|
content_dataThis property holds the data of the content. It can be read whatever the kind of content (backend-stored, external or packaged). However, only backend-stored and packaged can have their data safely modified. Trying to set the data of an external content will raise a `ValueError`. Its `content_url` must first be set to the empty string or a ``packaged:`` URL. See also `get_content_as_synced_file`.
|
content_is_textualThis property indicates if this element's content data can be handled as text. It uses the mimetypes registered with `advene.model.content.register.register_textual_mimetype`.
|
content_mimetypeThe mimetype of this element's content. If set to "x-advene/none", the other properties are erased and become unsettable. Note that it is only possible for relations.
|
content_modelThe resource used as the model of the content of this element. None if that content has no model. If the model can not be retrieved, an exception is raised. See also `get_content_model` and `content_model_id`.
|
content_model_idThe id-ref of the content model, or an empty string. This is a read-only property giving the id-ref of the resource held by `content_model`, or an empty string if there is no model. Note that this property is accessible even if the corresponding model is unreachable. See also `get_content_model` and `content_model`.
|
content_parsed
|
content_urlThis property holds the URL of the content, or an empty string. Its value determines whether the content is backend-stored, external or packaged. Note that setting a standard URL (i.e. not in the ``packaged:`` scheme) to a backend-stored or packaged URL will discard its data. On the other hand, changing from backend-store to packaged and vice-versa keeps the data. Finally, note that setting the URL to one in the ``packaged:`` model will automatically create a temporary directory and set the PACKAGED_ROOT metadata of the package to that directory.
|
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jul 8 16:00:02 2009 | http://epydoc.sourceforge.net |