2 SleekXMPP: The Sleek XMPP Library
3 Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of SleekXMPP.
6 See the file LICENSE for copying permission.
11 from sleekxmpp
import Iq
12 from sleekxmpp
.plugins
import BasePlugin
13 from sleekxmpp
.exceptions
import XMPPError
14 from sleekxmpp
.xmlstream
.handler
import Callback
15 from sleekxmpp
.xmlstream
.matcher
import StanzaPath
16 from sleekxmpp
.xmlstream
import register_stanza_plugin
17 from sleekxmpp
.plugins
.xep_0048
import stanza
, Bookmarks
, Conference
, URL
20 log
= logging
.getLogger(__name__
)
23 class XEP_0048(BasePlugin
):
26 description
= 'XEP-0048: Bookmarks'
27 dependencies
= set(['xep_0045', 'xep_0049', 'xep_0060', 'xep_0163', 'xep_0223'])
31 'storage_method': 'xep_0049'
34 def plugin_init(self
):
35 register_stanza_plugin(self
.xmpp
['xep_0060'].stanza
.Item
, Bookmarks
)
37 self
.xmpp
['xep_0049'].register(Bookmarks
)
38 self
.xmpp
['xep_0163'].register_pep('bookmarks', Bookmarks
)
40 self
.xmpp
.add_event_handler('session_start', self
._autojoin
)
43 self
.xmpp
.del_event_handler('session_start', self
._autojoin
)
45 def _autojoin(self
, __
):
46 if not self
.auto_join
:
50 result
= self
.get_bookmarks(method
=self
.storage_method
)
54 if self
.storage_method
== 'xep_0223':
55 bookmarks
= result
['pubsub']['items']['item']['bookmarks']
57 bookmarks
= result
['private']['bookmarks']
59 for conf
in bookmarks
['conferences']:
61 log
.debug('Auto joining %s as %s', conf
['jid'], conf
['nick'])
62 self
.xmpp
['xep_0045'].joinMUC(conf
['jid'], conf
['nick'],
63 password
=conf
['password'])
65 def set_bookmarks(self
, bookmarks
, method
=None, **iqargs
):
67 method
= self
.storage_method
68 return self
.xmpp
[method
].store(bookmarks
, **iqargs
)
70 def get_bookmarks(self
, method
=None, **iqargs
):
72 method
= self
.storage_method
74 loc
= 'storage:bookmarks' if method
== 'xep_0223' else 'bookmarks'
76 return self
.xmpp
[method
].retrieve(loc
, **iqargs
)