comparison src/plugins/plugin_xep_0060.py @ 301:e33b3a777f10

plugin xep-0060: added getEntry method
author Goffi <goffi@goffi.org>
date Mon, 21 Feb 2011 01:36:52 +0100
parents 7c79d4a8c9e6
children 2b52a5da0978
comparison
equal deleted inserted replaced
300:233e6fce0b49 301:e33b3a777f10
45 def __init__(self, host): 45 def __init__(self, host):
46 info(_("PubSub plugin initialization")) 46 info(_("PubSub plugin initialization"))
47 self.host = host 47 self.host = host
48 self.managedNodes=[] 48 self.managedNodes=[]
49 self.clients={} 49 self.clients={}
50 """host.bridge.addMethod("getItems", ".communication", in_sign='ssa{ss}s', out_sign='as', method=self.getItems,
51 async = True,
52 doc = { 'summary':'retrieve items',
53 'param_0':'service: pubsub service',
54 'param_1':'node: node identifier',
55 'param_2':'\n'.join(['options: can be:',
56 '- max_items: see XEP-0060 #6.5.7',
57 '- sub_id: subscription identifier, see XEP-0060 #7.2.2.2']),
58 'param_3':'%(doc_profile)s',
59 'return':'array of raw XML (content of the items)'
60 })"""
50 61
51 def getHandler(self, profile): 62 def getHandler(self, profile):
52 self.clients[profile] = SatPubSubClient(self.host, self) 63 self.clients[profile] = SatPubSubClient(self.host, self)
53 return self.clients[profile] 64 return self.clients[profile]
54 65
71 err_mess = _('INTERNAL ERROR: no handler for required profile') 82 err_mess = _('INTERNAL ERROR: no handler for required profile')
72 error(err_mess) 83 error(err_mess)
73 raise Exception(err_mess) 84 raise Exception(err_mess)
74 client.publish(service, nodeIdentifier, items, client.parent.jid) 85 client.publish(service, nodeIdentifier, items, client.parent.jid)
75 86
76 87 def getItems(self, service, node, max_items=None, sub_id=None, profile_key='@DEFAULT@'):
88 profile = self.host.memory.getProfileName(profile_key)
89 if not profile:
90 err_mess = _('Trying to get items with an unknown profile key [%s]') % profile_key
91 error(err_mess)
92 raise Exception(err_mess)
93 try:
94 client = self.clients[profile]
95 except KeyError:
96 err_mess = _('INTERNAL ERROR: no handler for required profile')
97 error(err_mess)
98 raise Exception(err_mess)
99 return client.items(service, node, max_items, sub_id, client.parent.jid)
100
77 class SatPubSubClient(pubsub.PubSubClient): 101 class SatPubSubClient(pubsub.PubSubClient):
78 implements(disco.IDisco) 102 implements(disco.IDisco)
79 103
80 def __init__(self, host, parent_plugin): 104 def __init__(self, host, parent_plugin):
81 self.host=host 105 self.host=host