Merge lp:~mhr3/zeitgeist/mimetypes into lp:zeitgeist/0.1

Proposed by Michal Hruby
Status: Rejected
Rejected by: Seif Lotfy
Proposed branch: lp:~mhr3/zeitgeist/mimetypes
Merge into: lp:zeitgeist/0.1
Diff against target: 500 lines (+248/-172)
5 files modified
_zeitgeist/loggers/datasources/recent.py (+2/-170)
test/engine-test.py (+25/-1)
test/test-mimetypes.py (+25/-0)
zeitgeist/Makefile.am (+2/-1)
zeitgeist/mimetypes.py (+194/-0)
To merge this branch: bzr merge lp:~mhr3/zeitgeist/mimetypes
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen visual review Needs Information
Review via email: mp+26233@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote :

Looks good on a quick glance over the diff. Nice work.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

While we are at improving our mime handling situation we might as well go the extra mile - especially now that we want to make it public API.

We now have interpretations like Interpretation.SPREADSHEET/PAGINATED_TEXT_DOCUMENT so we can do a much finer grained mapping of the mimetypes. This in turn works out beautifully with the queries because we now expand queries to also match all child types.

As an example take a look at my mimetype mappings libzeitgeist: http://bazaar.launchpad.net/~libzeitgeist-developers/libzeitgeist/trunk/annotate/head:/src/zeitgeist-mimetypes.c#L239

Anoter note: The public API should be added to our generated sphinx docs too...

review: Needs Information (visual review)
Revision history for this message
Markus Korn (thekorn) wrote :

I did not do a review yet, but I've one first comment: I don't like that we have the same logic in two places, in zeitgeist and in libzeitgeist. (and in the future also in C# and JS, ...)

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Perhaps we can compile the mimetype->interpretation map from some XML or JSON schemas, like we do for the ontologies, and have that be the authoritative place? For libzeitgeist I compile the ontology C-bindings from the Zeitgeist's Python module so there is no code dupe there. I could easily do the same for the mimetypes, but that requires a bit more structure in the mimetype spec than what is in Michal's proposal.

However doing all of this probably requires more work than I think we should put in for 0.3.4 at this point. I think the best route would be to either:

 1) Defer this task for post 0.3.4, or
 2) Make sure the implementation is done in a way so that we can add the extra introspection API for post 0.3.4 without breaking the mimetypes API from 0.3.4

I am not entirely sure which route I prefer, but I would hate to delay 0.3.4 more than we already have...

Revision history for this message
Seif Lotfy (seif) wrote :

Ok I am up for a mimetype-interpretation map:
I would prefer JSON for this issue...
what do u guys think?

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Why JSON and not straight Python? JSON would only slow down startup time, and Python already supports a very JSON-like syntax for declaring maps...

Revision history for this message
Seif Lotfy (seif) wrote :

Beacuse I think we want libzeitgeist and other languages to be able to
parse it... Or do u want to parse python syntax ?

On Mon, Jul 19, 2010 at 10:07 AM, Mikkel Kamstrup Erlandsen
<email address hidden> wrote:
> Why JSON and not straight Python? JSON would only slow down startup time, and Python already supports a very JSON-like syntax for declaring maps...
> --
> https://code.launchpad.net/~mhr3/zeitgeist/mimetypes/+merge/26233
> You are subscribed to branch lp:zeitgeist.
>

--
This is me doing some advertisement for my blog http://seilo.geekyogre.com

Revision history for this message
Markus Korn (thekorn) wrote :

This is not a reviewer comment, but I would like to add another possible way to solve this, python applications which would like to use this kind of mapper, could depend on libzeitgeist and use ctypes to access the mapper functions:

from ctypes import CDLL, c_char_p

libzeitgeist = CDLL("libzeitgeist-1.0.so.0")

interpretation_for_mimetype = libzeitgeist.zeitgeist_interpretation_for_mimetype
interpretation_for_mimetype.argtypes = [c_char_p,]
interpretation_for_mimetype.restype = c_char_p

print interpretation_for_mimetype("text/html")
print interpretation_for_mimetype("image/png")

manifestation_for_uri = libzeitgeist.zeitgeist_manifestation_for_uri
manifestation_for_uri.argtypes = [c_char_p,]
manifestation_for_uri.restype = c_char_p

print manifestation_for_uri("file:///home")
print manifestation_for_uri("http://www.google.de")

Revision history for this message
Siegfried Gevatter (rainct) wrote :

2010/7/19 Markus Korn <email address hidden>:
> This is not a reviewer comment, but I would like to add another possible way to solve this, python applications which would like to use this kind of mapper, could depend on libzeitgeist and use ctypes to access the mapper functions:

Eerk, making a real C->Python interface is not so difficult.

--
Siegfried-Angel Gevatter Pujals (RainCT)
Free Software Developer       363DEAE3

Revision history for this message
Michal Hruby (mhr3) wrote :

I think the cross-dependency of zg->libzg->zg is not a good idea, +1 for making it like the ontologies.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Markus, RainCT: Depending on libzeitgeist would add ~1mb to the Zeitgeist runtime I guess - which I think is a very steep price to pay for this.

As I noted in comment from 2010-05-28 I'd actually prefer a Python module for libzeitgeist, so I just write a small tool for libzeitgeist that outputs the C code at build time. Very easy for me, and fast and light for ZG.

Alternatively go full monty and write the autofoo magic that compiles some JSON/XML schema into Python code like we do for the ontology. In the end giving me a Python module to use in the libzeitgeist build process

Revision history for this message
Seif Lotfy (seif) wrote :

+1 for the alternative

On Mon, Jul 19, 2010 at 2:51 PM, Mikkel Kamstrup Erlandsen
<email address hidden> wrote:
> Markus, RainCT: Depending on libzeitgeist would add ~1mb to the Zeitgeist runtime I guess - which I think is a very steep price to pay for this.
>
> As I noted in comment from 2010-05-28 I'd actually prefer a Python module for libzeitgeist, so I just write a small tool for libzeitgeist that outputs the C code at build time. Very easy for me, and fast and light for ZG.
>
> Alternatively go full monty and write the autofoo magic that compiles some JSON/XML schema into Python code like we do for the ontology. In the end giving me a Python module to use in the libzeitgeist build process
> --
> https://code.launchpad.net/~mhr3/zeitgeist/mimetypes/+merge/26233
> You are subscribed to branch lp:zeitgeist.
>

--
This is me doing some advertisement for my blog http://seilo.geekyogre.com

Revision history for this message
Siegfried Gevatter (rainct) wrote :

Let's go with Python code, there's no reason to have it as JSON.

Revision history for this message
Seif Lotfy (seif) wrote :

Markus finished a module for that

Unmerged revisions

1460. By Michal Hruby

Interpretation.MUSIC -> Interpretation.AUDIO

1459. By Michal Hruby

Recent datasource: Use the zg.mimetypes module

1458. By Michal Hruby

Added mimetype to interpretation getter

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '_zeitgeist/loggers/datasources/recent.py'
--- _zeitgeist/loggers/datasources/recent.py 2010-04-29 11:33:01 +0000
+++ _zeitgeist/loggers/datasources/recent.py 2010-05-27 19:34:36 +0000
@@ -24,8 +24,6 @@
2424
25from __future__ import with_statement25from __future__ import with_statement
26import os26import os
27import re
28import fnmatch
29import urllib27import urllib
30import time28import time
31import logging29import logging
@@ -34,6 +32,7 @@
34from zeitgeist import _config32from zeitgeist import _config
35from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation, \33from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation, \
36 DataSource, get_timestamp_for_now34 DataSource, get_timestamp_for_now
35from zeitgeist.mimetypes import get_interpretation_for_mimetype
37from _zeitgeist.loggers.zeitgeist_base import DataProvider36from _zeitgeist.loggers.zeitgeist_base import DataProvider
3837
39log = logging.getLogger("zeitgeist.logger.datasources.recent")38log = logging.getLogger("zeitgeist.logger.datasources.recent")
@@ -51,166 +50,9 @@
51else:50else:
52 enabled = True51 enabled = True
5352
54class SimpleMatch(object):
55 """ Wrapper around fnmatch.fnmatch which allows to define mimetype
56 patterns by using shell-style wildcards.
57 """
58
59 def __init__(self, pattern):
60 self.__pattern = pattern
61
62 def match(self, text):
63 return fnmatch.fnmatch(text, self.__pattern)
64
65 def __repr__(self):
66 return "%s(%r)" %(self.__class__.__name__, self.__pattern)
67
68DOCUMENT_MIMETYPES = [
69 # Covers:
70 # vnd.corel-draw
71 # vnd.ms-powerpoint
72 # vnd.ms-excel
73 # vnd.oasis.opendocument.*
74 # vnd.stardivision.*
75 # vnd.sun.xml.*
76 SimpleMatch(u"application/vnd.*"),
77 # Covers: x-applix-word, x-applix-spreadsheet, x-applix-presents
78 SimpleMatch(u"application/x-applix-*"),
79 # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
80 re.compile(u"application/x-k(word|spread|presenter|illustrator)"),
81 u"application/ms-powerpoint",
82 u"application/msword",
83 u"application/pdf",
84 u"application/postscript",
85 u"application/ps",
86 u"application/rtf",
87 u"application/x-abiword",
88 u"application/x-gnucash",
89 u"application/x-gnumeric",
90 SimpleMatch(u"application/x-java*"),
91 SimpleMatch(u"*/x-tex"),
92 SimpleMatch(u"*/x-latex"),
93 SimpleMatch(u"*/x-dvi"),
94 u"text/plain"
95]
96
97IMAGE_MIMETYPES = [
98 # Covers:
99 # vnd.corel-draw
100 u"application/vnd.corel-draw",
101 # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
102 re.compile(u"application/x-k(word|spread|presenter|illustrator)"),
103 SimpleMatch(u"image/*"),
104]
105
106AUDIO_MIMETYPES = [
107 SimpleMatch(u"audio/*"),
108 u"application/ogg"
109]
110
111VIDEO_MIMETYPES = [
112 SimpleMatch(u"video/*"),
113 u"application/ogg"
114]
115
116DEVELOPMENT_MIMETYPES = [
117 u"application/ecmascript",
118 u"application/javascript",
119 u"application/x-csh",
120 u"application/x-designer",
121 u"application/x-desktop",
122 u"application/x-dia-diagram",
123 u"application/x-fluid",
124 u"application/x-glade",
125 u"application/xhtml+xml",
126 u"application/x-java-archive",
127 u"application/x-m4",
128 u"application/xml",
129 u"application/x-object",
130 u"application/x-perl",
131 u"application/x-php",
132 u"application/x-ruby",
133 u"application/x-shellscript",
134 u"application/x-sql",
135 u"text/css",
136 u"text/html",
137 u"text/x-c",
138 u"text/x-c++",
139 u"text/x-chdr",
140 u"text/x-copying",
141 u"text/x-credits",
142 u"text/x-csharp",
143 u"text/x-c++src",
144 u"text/x-csrc",
145 u"text/x-dsrc",
146 u"text/x-eiffel",
147 u"text/x-gettext-translation",
148 u"text/x-gettext-translation-template",
149 u"text/x-haskell",
150 u"text/x-idl",
151 u"text/x-java",
152 u"text/x-lisp",
153 u"text/x-lua",
154 u"text/x-makefile",
155 u"text/x-objcsrc",
156 u"text/x-ocaml",
157 u"text/x-pascal",
158 u"text/x-patch",
159 u"text/x-python",
160 u"text/x-sql",
161 u"text/x-tcl",
162 u"text/x-troff",
163 u"text/x-vala",
164 u"text/x-vhdl",
165]
166
167ALL_MIMETYPES = DOCUMENT_MIMETYPES + IMAGE_MIMETYPES + AUDIO_MIMETYPES + \
168 VIDEO_MIMETYPES + DEVELOPMENT_MIMETYPES
169
170class MimeTypeSet(set):
171 """ Set which allows to match against a string or an object with a
172 match() method.
173 """
174
175 def __init__(self, *items):
176 super(MimeTypeSet, self).__init__()
177 self.__pattern = set()
178 for item in items:
179 if isinstance(item, (str, unicode)):
180 self.add(item)
181 elif hasattr(item, "match"):
182 self.__pattern.add(item)
183 else:
184 raise ValueError("Bad mimetype '%s'" %item)
185
186 def __contains__(self, mimetype):
187 result = super(MimeTypeSet, self).__contains__(mimetype)
188 if not result:
189 for pattern in self.__pattern:
190 if pattern.match(mimetype):
191 return True
192 return result
193
194 def __len__(self):
195 return super(MimeTypeSet, self).__len__() + len(self.__pattern)
196
197 def __repr__(self):
198 items = ", ".join(sorted(map(repr, self | self.__pattern)))
199 return "%s(%s)" %(self.__class__.__name__, items)
200
20153
202class RecentlyUsedManagerGtk(DataProvider):54class RecentlyUsedManagerGtk(DataProvider):
203 55
204 FILTERS = {
205 # dict of name as key and the matching mimetypes as value
206 # if the value is None this filter matches all mimetypes
207 "DOCUMENT": MimeTypeSet(*DOCUMENT_MIMETYPES),
208 "IMAGE": MimeTypeSet(*IMAGE_MIMETYPES),
209 "MUSIC": MimeTypeSet(*AUDIO_MIMETYPES),
210 "VIDEO": MimeTypeSet(*VIDEO_MIMETYPES),
211 "SOURCE_CODE": MimeTypeSet(*DEVELOPMENT_MIMETYPES),
212 }
213
214 def __init__(self, client):56 def __init__(self, client):
215 DataProvider.__init__(self,57 DataProvider.__init__(self,
216 unique_id="com.zeitgeist-project,datahub,recent",58 unique_id="com.zeitgeist-project,datahub,recent",
@@ -269,16 +111,6 @@
269 pass # file may be a broken symlink (LP: #523761)111 pass # file may be a broken symlink (LP: #523761)
270 return None112 return None
271 113
272 def _get_interpretation_for_mimetype(self, mimetype):
273 matching_filter = None
274 for filter_name, mimetypes in self.FILTERS.iteritems():
275 if mimetype and mimetype in mimetypes:
276 matching_filter = filter_name
277 break
278 if matching_filter:
279 return getattr(Interpretation, matching_filter).uri
280 return ""
281
282 def _get_items(self):114 def _get_items(self):
283 # We save the start timestamp to avoid race conditions115 # We save the start timestamp to avoid race conditions
284 last_seen = get_timestamp_for_now()116 last_seen = get_timestamp_for_now()
@@ -297,7 +129,7 @@
297 129
298 subject = Subject.new_for_values(130 subject = Subject.new_for_values(
299 uri = unicode(uri),131 uri = unicode(uri),
300 interpretation = self._get_interpretation_for_mimetype(132 interpretation = get_interpretation_for_mimetype(
301 unicode(info.get_mime_type())),133 unicode(info.get_mime_type())),
302 manifestation = Manifestation.FILE_DATA_OBJECT.uri,134 manifestation = Manifestation.FILE_DATA_OBJECT.uri,
303 text = info.get_display_name(),135 text = info.get_display_name(),
304136
=== modified file 'test/engine-test.py'
--- test/engine-test.py 2010-05-15 13:15:44 +0000
+++ test/engine-test.py 2010-05-27 19:34:36 +0000
@@ -10,6 +10,7 @@
10from _zeitgeist.engine import constants10from _zeitgeist.engine import constants
11from _zeitgeist.engine import get_engine11from _zeitgeist.engine import get_engine
12from zeitgeist.datamodel import *12from zeitgeist.datamodel import *
13from zeitgeist.mimetypes import *
13from testutils import import_events14from testutils import import_events
1415
15import unittest16import unittest
@@ -366,7 +367,30 @@
366 self.assertEquals(2, len(result))367 self.assertEquals(2, len(result))
367 events = self.engine.get_events(result)368 events = self.engine.get_events(result)
368 369
369 370 def testMimetypeToInterpretation(self):
371 mimetype = "text/plain"
372 interpretation = get_interpretation_for_mimetype(mimetype)
373
374 event = Event()
375 event.interpretation = Manifestation.USER_ACTIVITY
376 event.manifestation = Interpretation.CREATE_EVENT
377 event.actor = "/usr/share/applications/gnome-about.desktop"
378
379 subject = Subject()
380 subject.uri = "file:///tmp/file.txt"
381 subject.manifestation = Manifestation.FILE_DATA_OBJECT
382 subject.interpretation = interpretation
383 subject.origin = "test://"
384 subject.mimetype = "text/plain"
385 subject.text = "This subject has no text"
386
387 event.append_subject(subject)
388 ids = self.engine.insert_events([event,])
389
390 results = self.engine.get_events([1])
391 self.assertEquals(1, len(results))
392 self.assertEquals(
393 interpretation, results[0].subjects[0].interpretation)
370 394
371 def testDontFindState(self):395 def testDontFindState(self):
372 # searchin by storage state is currently not implemented396 # searchin by storage state is currently not implemented
373397
=== added file 'test/test-mimetypes.py'
--- test/test-mimetypes.py 1970-01-01 00:00:00 +0000
+++ test/test-mimetypes.py 2010-05-27 19:34:36 +0000
@@ -0,0 +1,25 @@
1#! /usr/bin/python
2
3# Update python path to use local zeitgeist module
4import sys
5import os
6
7import zeitgeist.mimetypes
8
9# Test the mimetype -> Interpretation conversion
10mimetype = "image/png"
11i = zeitgeist.mimetypes.get_interpretation_for_mimetype(mimetype)
12print "Interpretation for %s: %s" % (mimetype, i)
13
14mimetype = "text/plain"
15i = zeitgeist.mimetypes.get_interpretation_for_mimetype(mimetype)
16print "Interpretation for %s: %s" % (mimetype, i)
17
18mimetype = "application/ogg"
19i = zeitgeist.mimetypes.get_interpretation_for_mimetype(mimetype)
20print "Interpretation for %s: %s" % (mimetype, i)
21
22mimetype = "unknown/invalid"
23i = zeitgeist.mimetypes.get_interpretation_for_mimetype(mimetype)
24print "Interpretation for %s: %s" % (mimetype, i)
25
026
=== modified file 'zeitgeist/Makefile.am'
--- zeitgeist/Makefile.am 2009-11-27 20:32:54 +0000
+++ zeitgeist/Makefile.am 2010-05-27 19:34:36 +0000
@@ -3,7 +3,8 @@
3app_PYTHON = \3app_PYTHON = \
4 __init__.py \4 __init__.py \
5 datamodel.py \5 datamodel.py \
6 client.py6 client.py \
7 mimetypes.py
78
8nodist_app_PYTHON = _config.py9nodist_app_PYTHON = _config.py
910
1011
=== added file 'zeitgeist/mimetypes.py'
--- zeitgeist/mimetypes.py 1970-01-01 00:00:00 +0000
+++ zeitgeist/mimetypes.py 2010-05-27 19:34:36 +0000
@@ -0,0 +1,194 @@
1# -.- coding: utf-8 -.-
2
3# Zeitgeist
4#
5# Copyright © 2009-2010 Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
6# Copyright © 2009 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com>
7# Copyright © 2009 Markus Korn <thekorn@gmx.de>
8# Copyright © 2010 Michal Hruby <michal.mhr@gmail.com>
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU Lesser General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU Lesser General Public License for more details.
19#
20# You should have received a copy of the GNU Lesser General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
23import re
24import fnmatch
25
26from zeitgeist.datamodel import Interpretation
27
28class SimpleMatch(object):
29 """ Wrapper around fnmatch.fnmatch which allows to define mimetype
30 patterns by using shell-style wildcards.
31 """
32
33 def __init__(self, pattern):
34 self.__pattern = pattern
35
36 def match(self, text):
37 return fnmatch.fnmatch(text, self.__pattern)
38
39 def __repr__(self):
40 return "%s(%r)" %(self.__class__.__name__, self.__pattern)
41
42class MimeTypeSet(set):
43 """ Set which allows to match against a string or an object with a
44 match() method.
45 """
46
47 def __init__(self, *items):
48 super(MimeTypeSet, self).__init__()
49 self.__pattern = set()
50 for item in items:
51 if isinstance(item, (str, unicode)):
52 self.add(item)
53 elif hasattr(item, "match"):
54 self.__pattern.add(item)
55 else:
56 raise ValueError("Bad mimetype '%s'" %item)
57
58 def __contains__(self, mimetype):
59 result = super(MimeTypeSet, self).__contains__(mimetype)
60 if not result:
61 for pattern in self.__pattern:
62 if pattern.match(mimetype):
63 return True
64 return result
65
66 def __len__(self):
67 return super(MimeTypeSet, self).__len__() + len(self.__pattern)
68
69 def __repr__(self):
70 items = ", ".join(sorted(map(repr, self | self.__pattern)))
71 return "%s(%s)" %(self.__class__.__name__, items)
72
73DOCUMENT_MIMETYPES = [
74 # Covers:
75 # vnd.corel-draw
76 # vnd.ms-powerpoint
77 # vnd.ms-excel
78 # vnd.oasis.opendocument.*
79 # vnd.stardivision.*
80 # vnd.sun.xml.*
81 SimpleMatch(u"application/vnd.*"),
82 # Covers: x-applix-word, x-applix-spreadsheet, x-applix-presents
83 SimpleMatch(u"application/x-applix-*"),
84 # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
85 re.compile(u"application/x-k(word|spread|presenter|illustrator)"),
86 u"application/ms-powerpoint",
87 u"application/msword",
88 u"application/pdf",
89 u"application/postscript",
90 u"application/ps",
91 u"application/rtf",
92 u"application/x-abiword",
93 u"application/x-gnucash",
94 u"application/x-gnumeric",
95 SimpleMatch(u"application/x-java*"),
96 SimpleMatch(u"*/x-tex"),
97 SimpleMatch(u"*/x-latex"),
98 SimpleMatch(u"*/x-dvi"),
99 u"text/plain"
100]
101
102IMAGE_MIMETYPES = [
103 # Covers:
104 # vnd.corel-draw
105 u"application/vnd.corel-draw",
106 # Covers: x-kword, x-kspread, x-kpresenter, x-killustrator
107 re.compile(u"application/x-k(word|spread|presenter|illustrator)"),
108 SimpleMatch(u"image/*"),
109]
110
111AUDIO_MIMETYPES = [
112 SimpleMatch(u"audio/*"),
113 u"application/ogg"
114]
115
116VIDEO_MIMETYPES = [
117 SimpleMatch(u"video/*"),
118 u"application/ogg"
119]
120
121DEVELOPMENT_MIMETYPES = [
122 u"application/ecmascript",
123 u"application/javascript",
124 u"application/x-csh",
125 u"application/x-designer",
126 u"application/x-desktop",
127 u"application/x-dia-diagram",
128 u"application/x-fluid",
129 u"application/x-glade",
130 u"application/xhtml+xml",
131 u"application/x-java-archive",
132 u"application/x-m4",
133 u"application/xml",
134 u"application/x-object",
135 u"application/x-perl",
136 u"application/x-php",
137 u"application/x-ruby",
138 u"application/x-shellscript",
139 u"application/x-sql",
140 u"text/css",
141 u"text/html",
142 u"text/x-c",
143 u"text/x-c++",
144 u"text/x-chdr",
145 u"text/x-copying",
146 u"text/x-credits",
147 u"text/x-csharp",
148 u"text/x-c++src",
149 u"text/x-csrc",
150 u"text/x-dsrc",
151 u"text/x-eiffel",
152 u"text/x-gettext-translation",
153 u"text/x-gettext-translation-template",
154 u"text/x-haskell",
155 u"text/x-idl",
156 u"text/x-java",
157 u"text/x-lisp",
158 u"text/x-lua",
159 u"text/x-makefile",
160 u"text/x-objcsrc",
161 u"text/x-ocaml",
162 u"text/x-pascal",
163 u"text/x-patch",
164 u"text/x-python",
165 u"text/x-sql",
166 u"text/x-tcl",
167 u"text/x-troff",
168 u"text/x-vala",
169 u"text/x-vhdl",
170]
171
172ALL_MIMETYPES = DOCUMENT_MIMETYPES + IMAGE_MIMETYPES + AUDIO_MIMETYPES + \
173 VIDEO_MIMETYPES + DEVELOPMENT_MIMETYPES
174
175FILTERS = {
176 # dict of name as key and the matching mimetypes as value
177 # if the value is None this filter matches all mimetypes
178 "DOCUMENT": MimeTypeSet(*DOCUMENT_MIMETYPES),
179 "IMAGE": MimeTypeSet(*IMAGE_MIMETYPES),
180 "AUDIO": MimeTypeSet(*AUDIO_MIMETYPES),
181 "VIDEO": MimeTypeSet(*VIDEO_MIMETYPES),
182 "SOURCE_CODE": MimeTypeSet(*DEVELOPMENT_MIMETYPES),
183}
184
185def get_interpretation_for_mimetype(mimetype):
186 matching_filter = None
187 for filter_name, mimetypes in FILTERS.iteritems():
188 if mimetype and mimetype in mimetypes:
189 matching_filter = filter_name
190 break
191 if matching_filter:
192 return getattr(Interpretation, matching_filter).uri
193 return ""
194