1 """I am the content handler for mimetype application/x-advene-builtin-view.
2 """
3
4 from inspect import getargspec
5
6 from advene.model.consts import _RAISE
7 from advene.model.core.element import \
8 MEDIA, ANNOTATION, RELATION, TAG, LIST, IMPORT, QUERY, VIEW, RESOURCE
9 from advene.model.exceptions import ContentHandlingError
14 """Is this view_handler likely to handle a view with that mimetype.
15
16 Return an int between 00 and 99, indicating the likelyhood of this handler
17 to handle correctly the given mimetype. 70 is used as a standard value when
18 the hanlder is pretty sure it can handle the mimetype.
19 """
20 if mimetype == "application/x-advene-builtin-view":
21 return 99
22 else:
23 return 0
24
26 """Return the mimetype of the content produced by that view.
27
28 Note that the output mimetype may depend on the mimetype of the view, as
29 well as the content of the view itself, but should not depend on the
30 element the view is applied to.
31 """
32 global _methods
33 params = view.content_parsed
34 return _methods[params["method"]].info["output_mimetype"]
35
47
54
66
76 return wrapper
77
78 _methods = {}
79
80
81 @_wrap_method(
82 output_mimetype = "text/plain",
83 )
86
87
88
89 @_wrap_method(
90 output_mimetype = "text/plain",
91 type = "one of the following values:\n" \
92 " * ANNOTATION\n * IMPORT\n * LIST\n * MEDIA\n * PACKAGE\n * QUERY\n" \
93 " * RELATION\n * RESOURCE\n * TAG\n * VIEW\n"""
94 )
96 d = { "ANNOTATION": ANNOTATION,
97 "IMPORT": IMPORT,
98 "LIST": LIST,
99 "MEDIA": MEDIA,
100 "PACKAGE": "Package",
101 "QUERY": QUERY,
102 "RELATION": RELATION,
103 "RESOURCE": RESOURCE,
104 "TAG": TAG,
105 "VIEW": VIEW,
106 }
107 type = d[type]
108 ref = getattr(obj, "ADVENE_TYPE", None)
109 if ref is None:
110 if obj.__class__.__name__ == "Package":
111 ref = "Package"
112
113 elif isinstance(basestring):
114 ref = RESOURCE
115 else:
116 try:
117 iter(obj)
118 except TypeError:
119 ref = None
120 else:
121 ref = LIST
122 if type == ref:
123 return "true"
124 else:
125 return ""
126
127
128 @_wrap_method(
129 output_mimetype = "text/plain",
130 mimetype = "a mimetype that the element's content mimetype, if any, must "\
131 "match"
132 )
134 if mimetype is not None:
135 m = getattr(obj, "content_mimetype", None)
136 if m is not None:
137 if m != mimetype:
138
139 return ""
140 return "true"
141
142
143