annotate src/plugins/plugin_xep_0060.py @ 628:42ee0b0b0a15

wix: fixed application quitting (fix bug 25)
author Goffi <goffi@goffi.org>
date Sun, 23 Jun 2013 01:42:12 +0200
parents 6f4c31192c7c
children 3c304929af74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
4 # SAT plugin for Publish-Subscribe (xep-0060)
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
10 # (at your option) any later version.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
15 # GNU Affero General Public License for more details.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 594
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
19
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from logging import debug, info, error
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
21
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
22 from wokkel import disco, pubsub
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
23
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from zope.interface import implements
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
25
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
26 PLUGIN_INFO = {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
27 "name": "Publish-Subscribe",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
28 "import_name": "XEP-0060",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
29 "type": "XEP",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
30 "protocols": ["XEP-0060"],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
31 "dependencies": [],
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
32 "main": "XEP_0060",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
33 "handler": "yes",
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
34 "description": _("""Implementation of PubSub Protocol""")
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
35 }
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
36
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
37
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
38 class XEP_0060(object):
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
39 OPT_ACCESS_MODEL = 'pubsub#access_model'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
40 OPT_PERSIST_ITEMS = 'pubsub#persist_items'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
41 OPT_MAX_ITEMS = 'pubsub#max_items'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
42 OPT_DELIVER_PAYLOADS = 'pubsub#deliver_payloads'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
43 OPT_SEND_ITEM_SUBSCRIBE = 'pubsub#send_item_subscribe'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
44 OPT_NODE_TYPE = 'pubsub#node_type'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
45 OPT_SUBSCRIPTION_TYPE = 'pubsub#subscription_type'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
46 OPT_SUBSCRIPTION_DEPTH = 'pubsub#subscription_depth'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
47 OPT_ROSTER_GROUPS_ALLOWED = 'pubsub#roster_groups_allowed'
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
48 OPT_PUBLISH_MODEL = 'pubsub#publish_model'
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
49
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
50 def __init__(self, host):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
51 info(_("PubSub plugin initialization"))
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.host = host
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
53 self.managedNodes = []
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
54 self.clients = {}
372
f964dcec1611 core: plugins refactored according to bridge + updatedValue now use profile
Goffi <goffi@goffi.org>
parents: 310
diff changeset
55 """host.bridge.addMethod("getItems", ".plugin", in_sign='ssa{ss}s', out_sign='as', method=self.getItems,
301
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
56 async = True,
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
57 doc = { 'summary':'retrieve items',
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
58 'param_0':'service: pubsub service',
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
59 'param_1':'node: node identifier',
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
60 'param_2':'\n'.join(['options: can be:',
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
61 '- max_items: see XEP-0060 #6.5.7',
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
62 '- sub_id: subscription identifier, see XEP-0060 #7.2.2.2']),
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
63 'param_3':'%(doc_profile)s',
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
64 'return':'array of raw XML (content of the items)'
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
65 })"""
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
66
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def getHandler(self, profile):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.clients[profile] = SatPubSubClient(self.host, self)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
69 return self.clients[profile]
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
70
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
71 def addManagedNode(self, node_name, callback):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
72 """Add a handler for a namespace
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
73 @param namespace: NS of the handler (will appear in disco info)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
74 @param callback: method to call when the handler is found
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
75 @param profile: profile which manage this handler"""
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.managedNodes.append((node_name, callback))
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
77
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
78 def __getClientNProfile(self, profile_key, action='do pusbsub'):
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
79 """Return a tuple of (client, profile)
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
80 raise error when the profile doesn't exists
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
81 @param profile_key: as usual :)
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
82 @param action: text of action to show in case of error"""
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
83 profile = self.host.memory.getProfileName(profile_key)
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
84 if not profile:
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
85 err_mess = _('Trying to %(action)s with an unknown profile key [%(profile_key)s]') % {
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
86 'action': action,
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
87 'profile_key': profile_key}
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
88 error(err_mess)
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
89 raise Exception(err_mess)
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
90 try:
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
91 client = self.clients[profile]
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
92 except KeyError:
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
93 err_mess = _('INTERNAL ERROR: no handler for required profile')
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
94 error(err_mess)
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
95 raise Exception(err_mess)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
96 return profile, client
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
97
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
98 def publish(self, service, nodeIdentifier, items=None, profile_key='@DEFAULT@'):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
99 profile, client = self.__getClientNProfile(profile_key, 'publish item')
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
100 return client.publish(service, nodeIdentifier, items, client.parent.jid)
286
3b382fa0ac28 plugin xep-0163: added mood publishing
Goffi <goffi@goffi.org>
parents: 283
diff changeset
101
301
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
102 def getItems(self, service, node, max_items=None, sub_id=None, profile_key='@DEFAULT@'):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
103 profile, client = self.__getClientNProfile(profile_key, 'get items')
301
e33b3a777f10 plugin xep-0060: added getEntry method
Goffi <goffi@goffi.org>
parents: 291
diff changeset
104 return client.items(service, node, max_items, sub_id, client.parent.jid)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
105
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
106 def getOptions(self, service, nodeIdentifier, subscriber, subscriptionIdentifier=None, profile_key='@DEFAULT@'):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
107 profile, client = self.__getClientNProfile(profile_key, 'get options')
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
108 return client.getOptions(service, nodeIdentifier, subscriber, subscriptionIdentifier)
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
109
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
110 def setOptions(self, service, nodeIdentifier, subscriber, options, subscriptionIdentifier=None, profile_key='@DEFAULT@'):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
111 profile, client = self.__getClientNProfile(profile_key, 'set options')
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
112 return client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
113
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
114 def createNode(self, service, nodeIdentifier, options, profile_key='@DEFAULT@'):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
115 profile, client = self.__getClientNProfile(profile_key, 'create node')
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
116 return client.createNode(service, nodeIdentifier, options)
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
117
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
118 def deleteNode(self, service, nodeIdentifier, profile_key='@DEFAULT@'):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
119 profile, client = self.__getClientNProfile(profile_key, 'delete node')
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
120 return client.deleteNode(service, nodeIdentifier)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
121
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
122 def subscribe(self, service, nodeIdentifier, sub_jid=None, options=None, profile_key='@DEFAULT@'):
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
123 profile, client = self.__getClientNProfile(profile_key, 'subscribe node')
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
124 return client.subscribe(service, nodeIdentifier, sub_jid or client.parent.jid.userhostJID(), options=options)
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
125
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
126
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
127 class SatPubSubClient(pubsub.PubSubClient):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
128 implements(disco.IDisco)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
129
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
130 def __init__(self, host, parent_plugin):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
131 self.host = host
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self.parent_plugin = parent_plugin
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
133 pubsub.PubSubClient.__init__(self)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
134
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
135 def connectionInitialized(self):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
136 pubsub.PubSubClient.connectionInitialized(self)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
137
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
138 def itemsReceived(self, event):
477
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 459
diff changeset
139 if not self.host.trigger.point("PubSubItemsReceived", event, self.parent.profile):
031b0e0aaab8 plugin groupblog: subscriptions/notifications
Goffi <goffi@goffi.org>
parents: 459
diff changeset
140 return
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
141 for node in self.parent_plugin.managedNodes:
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
142 if event.nodeIdentifier == node[0]:
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
143 return node[1](event, self.parent.profile)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
144
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
145 def deleteReceived(self, event):
303
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
146 #TODO: manage delete event
2b52a5da0978 plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents: 301
diff changeset
147 debug(_("Publish node deleted"))
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
148
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
149 # def purgeReceived(self, event):
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
150
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
151
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
152
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
153 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
154 _disco_info = []
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
155 self.host.trigger.point("PubSub Disco Info", _disco_info, self.parent.profile)
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
156 return _disco_info
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
157
283
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
158 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
68cd30d982a5 core: added plugins for PubSub et PEP (first drafts)
Goffi <goffi@goffi.org>
parents:
diff changeset
159 return []