2 Slixmpp: The Slick XMPP Library
3 Copyright (C) 2010 Nathanael C. Fritz, Erik Reuterborg Larsson
4 This file is part of Slixmpp.
6 See the file LICENSE for copying permission.
9 from slixmpp
.xmlstream
import ElementBase
, ET
10 from slixmpp
.plugins
.xep_0030
.stanza
.items
import DiscoItems
13 class Set(ElementBase
):
16 XEP-0059 (Result Set Managment) can be used to manage the
17 results of queries. For example, limiting the number of items
18 per response or starting at certain positions.
22 <query xmlns="http://jabber.org/protocol/disco#items">
23 <set xmlns="http://jabber.org/protocol/rsm">
30 <query xmlns="http://jabber.org/protocol/disco#items">
31 <item jid="conference.example.com" />
32 <item jid="pubsub.example.com" />
33 <set xmlns="http://jabber.org/protocol/rsm">
34 <first>conference.example.com</first>
35 <last>pubsub.example.com</last>
41 first_index -- The index attribute of <first>
42 after -- The id defining from which item to start
43 before -- The id defining from which item to
44 start when browsing backwards
45 max -- Max amount per response
46 first -- Id for the first item in the response
47 last -- Id for the last item in the response
48 index -- Used to set an index to start from
49 count -- The number of remote items available
52 set_first_index -- Sets the index attribute for <first> and
53 creates the element if it doesn't exist
54 get_first_index -- Returns the value of the index
56 del_first_index -- Removes the index attribute for <first>
58 set_before -- Sets the value of <before>, if the value is True
59 then the element will be created without a value
60 get_before -- Returns the value of <before>, if it is
61 empty it will return True
64 namespace
= 'http://jabber.org/protocol/rsm'
67 sub_interfaces
= set(('first', 'after', 'before', 'count',
68 'index', 'last', 'max'))
69 interfaces
= set(('first_index', 'first', 'after', 'before',
70 'count', 'index', 'last', 'max'))
72 def set_first_index(self
, val
):
73 fi
= self
.find("{%s}first" % (self
.namespace
))
76 fi
.attrib
['index'] = val
77 elif 'index' in fi
.attrib
:
78 del fi
.attrib
['index']
80 fi
= ET
.Element("{%s}first" % (self
.namespace
))
81 fi
.attrib
['index'] = val
84 def get_first_index(self
):
85 fi
= self
.find("{%s}first" % (self
.namespace
))
87 return fi
.attrib
.get('index', '')
89 def del_first_index(self
):
90 fi
= self
.xml
.find("{%s}first" % (self
.namespace
))
92 del fi
.attrib
['index']
94 def set_before(self
, val
):
95 b
= self
.xml
.find("{%s}before" % (self
.namespace
))
96 if b
is None and val
is True:
97 self
._set
_sub
_text
('{%s}before' % self
.namespace
, '', True)
99 self
._set
_sub
_text
('{%s}before' % self
.namespace
, val
)
101 def get_before(self
):
102 b
= self
.xml
.find("{%s}before" % (self
.namespace
))
103 if b
is not None and not b
.text
: