comparison sat_pubsub/backend.py @ 314:1e546442b81a

backend (getItems): minor refactoring of extenstion callback loop, as it is used only for RSM and it is not efficient. Need to be moved in an other module
author Goffi <goffi@goffi.org>
date Sun, 03 Jan 2016 18:33:22 +0100
parents 5d7c3787672e
children 720d73e30bf7
comparison
equal deleted inserted replaced
313:e8e1ca94fd8c 314:1e546442b81a
641 d = node.getItems(authorized_groups, unrestricted, maxItems, ext_data) 641 d = node.getItems(authorized_groups, unrestricted, maxItems, ext_data)
642 if unrestricted: 642 if unrestricted:
643 d.addCallback(self._tuple2ItemData) 643 d.addCallback(self._tuple2ItemData)
644 d.addCallback(append_item_config) 644 d.addCallback(append_item_config)
645 645
646 for extension in ext_data: 646 try:
647 if ext_data[extension] is not None: 647 rsm_data = ext_data['rsm']
648 if hasattr(self, '_items_%s' % extension): 648 except KeyError:
649 method = getattr(self, '_items_%s' % extension) 649 pass
650 d.addCallback(method, node, authorized_groups, 650 else:
651 unrestricted, maxItems, itemIdentifiers, 651 if rsm_data is not None:
652 ext_data[extension]) 652 d.addCallback(self._items_rsm, node, authorized_groups,
653 unrestricted, maxItems, itemIdentifiers,
654 rsm_data)
653 return d 655 return d
654 656
655 if not ILeafNode.providedBy(node): 657 if not ILeafNode.providedBy(node):
656 return [] 658 return []
657 659
678 680
679 return d 681 return d
680 682
681 def _items_rsm(self, elts, node, authorized_groups, unrestricted, maxItems, 683 def _items_rsm(self, elts, node, authorized_groups, unrestricted, maxItems,
682 itemIdentifiers, request): 684 itemIdentifiers, request):
685 # FIXME: move this to a separate module ?
683 response = rsm.RSMResponse() 686 response = rsm.RSMResponse()
684 687
685 d_count = node.countItems(authorized_groups, unrestricted) 688 d_count = node.countItems(authorized_groups, unrestricted)
686 d_count.addCallback(lambda count: setattr(response, 'count', count)) 689 d_count.addCallback(lambda count: setattr(response, 'count', count))
687 d_list = [d_count] 690 d_list = [d_count]