XEP-0059: Result Set Management#
- class slixmpp.plugins.xep_0059.XEP_0059(xmpp, config=None)[source]#
XEP-0059: Result Set Management
- iterate(stanza, interface, results='substanzas', amount=10, reverse=False, recv_interface=None, pre_cb=None, post_cb=None, iq_options=None)[source]#
Create a new result set iterator for a given stanza query.
- Parameters
stanza (
Iq
) – A stanza object to serve as a template for queries made each iteration. For example, a basic disco#items query.interface (
str
) – The name of the substanza to which the result set management stanza should be appended in the query stanza. For example, for disco#items queries the interface ‘disco_items’ should be used.recv_interface (
Optional
[str
]) – The name of the substanza from which the result set management stanza should be read in the result stanza. If unspecified, it will be set to the same value as theinterface
parameter.pre_cb (
Optional
[Callable
[[Iq
],None
]]) – Callback to run before sending each stanza e.g. setting the MAM queryid and starting a stanza collector.post_cb (
Optional
[Callable
[[Iq
],None
]]) – Callback to run after receiving each stanza e.g. stopping a MAM stanza collector in order to gather results.results (
str
) – The name of the interface containing the query results (typically just ‘substanzas’).iq_options (
Optional
[Dict
[str
,Any
]]) – Optional dict of parameters for Iq.send
- Return type
- class slixmpp.plugins.xep_0059.ResultIterator(query, interface, results='substanzas', amount=10, start=None, reverse=False, recv_interface=None, pre_cb=None, post_cb=None, iq_options=None)[source]#
An iterator for Result Set Management
Example:
q = Iq() q['to'] = 'pubsub.example.com' q['disco_items']['node'] = 'blog' async for i in ResultIterator(q, 'disco_items', '10'): print(i['disco_items']['items'])
- query: slixmpp.stanza.iq.Iq#
Template for the RSM query
- amount: int#
Amount of elements to retrieve for each page
- start: Optional[str]#
From which item id to start
- iq_options: Dict[str, Any]#
Optional dict of Iq options (timeout, etc…) for Iq.send()
- interface: str#
Substanza of the query to send, e.g. “disco_items”
- pre_cb: Optional[Callable[[slixmpp.stanza.iq.Iq], None]]#
Callback to run before sending the stanza
- post_cb: Optional[Callable[[slixmpp.stanza.iq.Iq], None]]#
Callback to run after receiving the reply
- results: str#
Stanza interface on the query results providing the retrieved elements (used to count them)
- reverse: bool#
If True, page backwards through the results
Stanza elements#
- class slixmpp.plugins.xep_0059.stanza.Set(xml=None, parent=None)[source]#
XEP-0059 (Result Set Management) can be used to manage the results of queries. For example, limiting the number of items per response or starting at certain positions.
Example set stanzas:
<iq type="get"> <query xmlns="http://jabber.org/protocol/disco#items"> <set xmlns="http://jabber.org/protocol/rsm"> <max>2</max> </set> </query> </iq> <iq type="result"> <query xmlns="http://jabber.org/protocol/disco#items"> <item jid="conference.example.com" /> <item jid="pubsub.example.com" /> <set xmlns="http://jabber.org/protocol/rsm"> <first>conference.example.com</first> <last>pubsub.example.com</last> </set> </query> </iq>
Stanza Interface:
first_index -- The index attribute of <first> after -- The id defining from which item to start before -- The id defining from which item to start when browsing backwards max -- Max amount per response first -- Id for the first item in the response last -- Id for the last item in the response index -- Used to set an index to start from count -- The number of remote items available
- interfaces: ClassVar[Set[str]] = {'after', 'before', 'count', 'first', 'first_index', 'index', 'last', 'max'}#
The set of keys that the stanza provides for accessing and manipulating the underlying XML object. This set may be augmented with the
plugin_attrib
value of any registered stanza plugins.
- iterables: List[ElementBase]#
A list of child stanzas whose class is included in
plugin_iterables
.
- name: ClassVar[str] = 'set'#
The XML tag name of the element, not including any namespace prefixes. For example, an
ElementBase
object for<message />
would usename = 'message'
.
- namespace: str = 'http://jabber.org/protocol/rsm'#
The XML namespace for the element. Given
<foo xmlns="bar" />
, thennamespace = "bar"
should be used. The default namespace isjabber:client
since this is being used in an XMPP library.
- parent: Optional[ReferenceType[ElementBase]]#
A
weakref.weakref
to the parent stanza, if there is one. If not, thenparent
isNone
.
- plugin_attrib: ClassVar[str] = 'rsm'#
For
ElementBase
subclasses which are intended to be used as plugins, theplugin_attrib
value defines the plugin name. Plugins may be accessed by using theplugin_attrib
value as the interface. An example usingplugin_attrib = 'foo'
:register_stanza_plugin(Message, FooPlugin) msg = Message() msg['foo']['an_interface_from_the_foo_plugin']
- plugins: Dict[Tuple[str, Optional[str]], ElementBase]#
An ordered dictionary of plugin stanzas, mapped by their
plugin_attrib
value.
- set_before(val)[source]#
Sets the value of <before>, if the value is True then the element will be created without a value
- set_first_index(val)[source]#
Sets the index attribute for <first> and creates the element if it doesn’t exist
- sub_interfaces: ClassVar[Set[str]] = {'after', 'before', 'count', 'first', 'index', 'last', 'max'}#
A subset of
interfaces
which maps interfaces to direct subelements of the underlying XML object. Using this set, the text of these subelements may be set, retrieved, or removed without needing to define custom methods.
- tag: str#
The name of the tag for the stanza’s root element. It is the same as calling
tag_name()
and is formatted as'{namespace}elementname'
.
- xml: ET.Element#
The underlying XML object for the stanza. It is a standard
xml.etree.ElementTree
object.