| Trees | Indices | Help |
|
|---|
File metadata management. The `trac.mimeview` package centralizes the intelligence related to file metadata, principally concerning the `type` (MIME type) of the content and, if relevant, concerning the text encoding (charset) used by the content. There are primarily two approaches for getting the MIME type of a given file: * taking advantage of existing conventions for the file name * examining the file content and applying various heuristics The module also knows how to convert the file content from one type to another type. In some cases, only the `url` pointing to the file's content is actually needed, that's why we avoid to read the file's content when it's not needed. The actual `content` to be converted might be a `unicode` object, but it can also be the raw byte string (`str`) object, or simply an object that can be `read()`. ---- NOTE: for plugin developers The Mimeview API is quite complex and many things there are currently a bit difficult to work with (e.g. what an actual `content` might be, see the last paragraph of this description). So this area is mainly in a ''work in progress'' state, which will be improved upon in the near future (see [trac:ticket:3332 #3332]). In particular, if you are interested in writing `IContentConverter` and `IHTMLPreviewRenderer` components, note that those interfaces will be merged into a new style `IContentConverter`. Feel free to contribute remarks and suggestions for improvements to the corresponding ticket ([trac:ticket:3332 #3332]).
{'AUTHORS': 'text/plain', 'C': 'text/x-c++src', 'C#': 'text/x-...)unicode object from a content to be previewed.
source code
{'AUTHORS': 'text/plain', 'C': 'text/x-c++src', 'C#': 'text/x-...)
Guess the most probable MIME type of a file with the given name.
filename is either a filename (the lookup will then use the suffix)
or some arbitrary keyword.
content is either a str or an unicode string.
Detect binary content by checking the first thousand bytes for zeroes.
Operate on either str or unicode strings.
Detect different unicode charsets by looking for BOMs (Byte Order Mark).
Operate obviously only on str objects.
Retrieve an unicode object from a content to be previewed.
In case the raw content had an unicode BOM, we remove it.
>>> from trac.test import EnvironmentStub >>> env = EnvironmentStub() >>> content_to_unicode(env, u"\ufeffNo BOM! h\u00e9 !", '') u'No BOM! h\xe9 !' >>> content_to_unicode(env, "No BOM! hé !", '') u'No BOM! h\xe9 !'
| Trees | Indices | Help |
|
|---|