Mercurial > libervia-pubsub
comparison idavoll/pubsub.py @ 147:fee92e499d6d
Changed Data Forms implementation to support all field types and
options in case of list-single and list-multi.
Strip the options before returning meta data in disco#info request to a node.
Fix error handling in disco#info handling to not mask unexpected exceptions.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Fri, 29 Jul 2005 15:38:29 +0000 |
parents | d2c18d88f618 |
children | 043f2e5ce8cd |
comparison
equal
deleted
inserted
replaced
146:b4490bdc77e5 | 147:fee92e499d6d |
---|---|
151 if self.backend.supports_publisher_affiliation(): | 151 if self.backend.supports_publisher_affiliation(): |
152 info.append(disco.Feature(NS_PUBSUB + "#publisher-affiliation")) | 152 info.append(disco.Feature(NS_PUBSUB + "#publisher-affiliation")) |
153 | 153 |
154 return defer.succeed(info) | 154 return defer.succeed(info) |
155 else: | 155 else: |
156 try: | 156 def trap_not_found(result): |
157 d = self.backend.get_node_type(node) | 157 result.trap(storage.NodeNotFound) |
158 d.addCallback(self._add_identity, [], node) | 158 return [] |
159 d.addErrback(lambda _: []) | 159 |
160 except storage.NodeNotFound: | 160 d = self.backend.get_node_type(node) |
161 return defer.succeed([]) | 161 d.addCallback(self._add_identity, [], node) |
162 d.addErrback(trap_not_found) | |
162 return d | 163 return d |
163 | 164 |
164 def _add_identity(self, node_type, result_list, node): | 165 def _add_identity(self, node_type, result_list, node): |
165 result_list.append(disco.Identity('pubsub', node_type)) | 166 result_list.append(disco.Identity('pubsub', node_type)) |
166 d = self.backend.get_node_meta_data(node) | 167 d = self.backend.get_node_meta_data(node) |
167 d.addCallback(self._add_meta_data, node_type, result_list) | 168 d.addCallback(self._add_meta_data, node_type, result_list) |
168 return d | 169 return d |
169 | 170 |
170 def _add_meta_data(self, meta_data, node_type, result_list): | 171 def _add_meta_data(self, meta_data, node_type, result_list): |
171 form = data_form.Form(type="result", form_type=NS_PUBSUB + "#meta-data") | 172 form = data_form.Form(type="result", form_type=NS_PUBSUB + "#meta-data") |
173 | |
172 for meta_datum in meta_data: | 174 for meta_datum in meta_data: |
173 form.add_field_single(**meta_datum) | 175 try: |
174 form.add_field_single("text-single", | 176 del meta_datum['options'] |
175 "pubsub#node_type", | 177 except KeyError: |
176 "The type of node (collection or leaf)", | 178 pass |
177 node_type) | 179 |
180 form.add_field(**meta_datum) | |
181 | |
182 form.add_field("text-single", | |
183 "pubsub#node_type", | |
184 "The type of node (collection or leaf)", | |
185 node_type) | |
178 result_list.append(form) | 186 result_list.append(form) |
179 return result_list | 187 return result_list |
180 | 188 |
181 def get_disco_items(self, node): | 189 def get_disco_items(self, node): |
182 if node or self.hide_nodes: | 190 if node or self.hide_nodes: |
374 configure["node"] = node_id | 382 configure["node"] = node_id |
375 form = data_form.Form(type="form", | 383 form = data_form.Form(type="form", |
376 form_type=NS_PUBSUB + "#node_config") | 384 form_type=NS_PUBSUB + "#node_config") |
377 | 385 |
378 for option in options: | 386 for option in options: |
379 form.add_field_single(**option) | 387 form.add_field(**option) |
380 | 388 |
381 form.parent = configure | 389 form.parent = configure |
382 configure.addChild(form) | 390 configure.addChild(form) |
383 | 391 |
384 return [reply] | 392 return [reply] |