From c66a4d4097a249efc029b761d6150378a54bf702 Mon Sep 17 00:00:00 2001 From: mathieui Date: Tue, 24 Feb 2015 18:58:40 +0100 Subject: Update the documentation and examples - update most of the examples with slixmpp - change the help channels pointed out in the doc - add a page listing differences from slixmpp and how to use asyncio nicely with slixmpp - fix some in-code rst documentation --- slixmpp/stanza/iq.py | 70 ++++++++++++++++++----------------------- slixmpp/stanza/message.py | 50 +++++++++++++++-------------- slixmpp/stanza/presence.py | 43 ++++++++++--------------- slixmpp/xmlstream/stanzabase.py | 6 ++-- 4 files changed, 76 insertions(+), 93 deletions(-) (limited to 'slixmpp') diff --git a/slixmpp/stanza/iq.py b/slixmpp/stanza/iq.py index bb46aecc..f7b222e6 100644 --- a/slixmpp/stanza/iq.py +++ b/slixmpp/stanza/iq.py @@ -32,6 +32,9 @@ class Iq(RootStanza): as a carrier stanza for an application-specific protocol instead. Example Stanzas: + + .. code-block:: xml + @@ -47,20 +50,9 @@ class Iq(RootStanza): Stanza Interface: - query -- The namespace of the element if one exists. - + - **query**: The namespace of the element if one exists. Attributes: - types -- May be one of: get, set, result, or error. - - Methods: - __init__ -- Overrides StanzaBase.__init__. - unhandled -- Send error if there are no handlers. - set_payload -- Overrides StanzaBase.set_payload. - set_query -- Add or modify a element. - get_query -- Return the namespace of the element. - del_query -- Remove the element. - reply -- Overrides StanzaBase.reply - send -- Overrides StanzaBase.send + - **types**: May be one of: get, set, result, or error. """ namespace = 'jabber:client' @@ -98,8 +90,9 @@ class Iq(RootStanza): """ Set the XML contents of the stanza. - Arguments: - value -- An XML object to use as the stanza's contents + :param value: An XML object or a list of XML objects to use as the + stanza's contents + :type value: list or XML object """ self.clear() StanzaBase.set_payload(self, value) @@ -111,8 +104,7 @@ class Iq(RootStanza): Query elements are differentiated by their namespace. - Arguments: - value -- The namespace of the element. + :param str value: The namespace of the element. """ query = self.xml.find("{%s}query" % value) if query is None and value: @@ -126,7 +118,9 @@ class Iq(RootStanza): return self def get_query(self): - """Return the namespace of the element.""" + """Return the namespace of the element. + + :rtype: str""" for child in self.xml: if child.tag.endswith('query'): ns = child.tag.split('}')[0] @@ -144,16 +138,15 @@ class Iq(RootStanza): def reply(self, clear=True): """ - Send a reply stanza. + Create a new stanza replying to ``self``. Overrides StanzaBase.reply Sets the 'type' to 'result' in addition to the default StanzaBase.reply behavior. - Arguments: - clear -- Indicates if existing content should be - removed before replying. Defaults to True. + :param bool clear: Indicates if existing content should be + removed before replying. Defaults to True. """ new_iq = StanzaBase.reply(self, clear=clear) new_iq['type'] = 'result' @@ -168,10 +161,8 @@ class Iq(RootStanza): Overrides StanzaBase.send - Arguments: - - timeout -- The length of time (in seconds) to wait for a - response before an IqTimeout is raised + :param int timeout: The length of time (in seconds) to wait for a + response before an IqTimeout is raised """ future = asyncio.Future() @@ -216,20 +207,19 @@ class Iq(RootStanza): Overrides StanzaBase.send - Arguments: - - callback -- Optional reference to a stream handler - function. Will be executed when a reply stanza is - received. - timeout -- The length of time (in seconds) to wait for a - response before the timeout_callback is called, - instead of the regular callback - timeout_callback -- Optional reference to a stream handler - function. Will be executed when the timeout expires - before a response has been received with the - originally-sent IQ stanza. - coroutine -- This function will return a coroutine if this argument - is True. + :param function callback: Optional reference to a stream handler + function. Will be executed when a reply + stanza is received. + :param int timeout: The length of time (in seconds) to wait for a + response before the timeout_callback is called, + instead of the regular callback + :param function timeout_callback: Optional reference to a stream handler + function. Will be executed when the + timeout expires before a response has + been received for the originally-sent + IQ stanza. + :param bool coroutine: This function will return a coroutine if this + argument is True. """ if self.stream.session_bind_event.is_set(): matcher = MatchIDSender({ diff --git a/slixmpp/stanza/message.py b/slixmpp/stanza/message.py index 7f9e90f5..cbb170fa 100644 --- a/slixmpp/stanza/message.py +++ b/slixmpp/stanza/message.py @@ -23,6 +23,9 @@ class Message(RootStanza): an error response. Example stanzas: + + .. code-block:: xml + Hi! @@ -32,26 +35,13 @@ class Message(RootStanza): Stanza Interface: - body -- The main contents of the message. - subject -- An optional description of the message's contents. - mucroom -- (Read-only) The name of the MUC room that sent the message. - mucnick -- (Read-only) The MUC nickname of message's sender. + - **body**: The main contents of the message. + - **subject**: An optional description of the message's contents. + - **mucroom**: (Read-only) The name of the MUC room that sent the message. + - **mucnick**: (Read-only) The MUC nickname of message's sender. Attributes: - types -- May be one of: normal, chat, headline, groupchat, or error. - - Methods: - setup -- Overrides StanzaBase.setup. - chat -- Set the message type to 'chat'. - normal -- Set the message type to 'normal'. - reply -- Overrides StanzaBase.reply - get_type -- Overrides StanzaBase interface - get_mucroom -- Return the name of the MUC room of the message. - set_mucroom -- Dummy method to prevent assignment. - del_mucroom -- Dummy method to prevent deletion. - get_mucnick -- Return the MUC nickname of the message's sender. - set_mucnick -- Dummy method to prevent assignment. - del_mucnick -- Dummy method to prevent deletion. + - **types**: May be one of: normal, chat, headline, groupchat, or error. """ name = 'message' @@ -81,18 +71,25 @@ class Message(RootStanza): Overrides default stanza interface behavior. Returns 'normal' if no type attribute is present. + + :rtype: str """ return self._get_attr('type', 'normal') def get_parent_thread(self): - """Return the message thread's parent thread.""" + """Return the message thread's parent thread. + + :rtype: str + """ thread = self.xml.find('{%s}thread' % self.namespace) if thread is not None: return thread.attrib.get('parent', '') return '' def set_parent_thread(self, value): - """Add or change the message thread's parent thread.""" + """Add or change the message thread's parent thread. + + :param str value: identifier of the thread""" thread = self.xml.find('{%s}thread' % self.namespace) if value: if thread is None: @@ -128,10 +125,11 @@ class Message(RootStanza): Sets proper 'to' attribute if the message is from a MUC, and adds a message body if one is given. - Arguments: - body -- Optional text content for the message. - clear -- Indicates if existing content should be removed - before replying. Defaults to True. + :param str body: Optional text content for the message. + :param bool clear: Indicates if existing content should be removed + before replying. Defaults to True. + + :rtype: :class:`~.Message` """ new_message = StanzaBase.reply(self, clear) @@ -152,6 +150,8 @@ class Message(RootStanza): Return the name of the MUC room where the message originated. Read-only stanza interface. + + :rtype: str """ if self['type'] == 'groupchat': return self['from'].bare @@ -163,6 +163,8 @@ class Message(RootStanza): Return the nickname of the MUC user that sent the message. Read-only stanza interface. + + :rtype: str """ if self['type'] == 'groupchat': return self['from'].resource diff --git a/slixmpp/stanza/presence.py b/slixmpp/stanza/presence.py index e1b8c0bc..1e8a940e 100644 --- a/slixmpp/stanza/presence.py +++ b/slixmpp/stanza/presence.py @@ -27,6 +27,9 @@ class Presence(RootStanza): to help keep the network running smoothly. Example stanzas: + + .. code-block:: xml + @@ -40,24 +43,14 @@ class Presence(RootStanza): Stanza Interface: - priority -- A value used by servers to determine message routing. - show -- The type of status, such as away or available for chat. - status -- Custom, human readable status message. + - **priority**: A value used by servers to determine message routing. + - **show**: The type of status, such as away or available for chat. + - **status**: Custom, human readable status message. Attributes: - types -- One of: available, unavailable, error, probe, - subscribe, subscribed, unsubscribe, - and unsubscribed. - showtypes -- One of: away, chat, dnd, and xa. - - Methods: - setup -- Overrides StanzaBase.setup - reply -- Overrides StanzaBase.reply - set_show -- Set the value of the element. - get_type -- Get the value of the type attribute or element. - set_type -- Set the value of the type attribute or element. - get_priority -- Get the value of the element. - set_priority -- Set the value of the element. + - **types**: One of: available, unavailable, error, probe, + subscribe, subscribed, unsubscribe, and unsubscribed. + - **showtypes**: One of: away, chat, dnd, and xa. """ name = 'presence' @@ -93,8 +86,7 @@ class Presence(RootStanza): """ Set the value of the element. - Arguments: - show -- Must be one of: away, chat, dnd, or xa. + :param str show: Must be one of: away, chat, dnd, or xa. """ if show is None: self._del_sub('show') @@ -119,8 +111,7 @@ class Presence(RootStanza): Set the type attribute's value, and the element if applicable. - Arguments: - value -- Must be in either self.types or self.showtypes. + :param str value: Must be in either self.types or self.showtypes. """ if value in self.types: self['show'] = None @@ -146,14 +137,15 @@ class Presence(RootStanza): Bot clients should typically use a priority of 0 if the same JID is used elsewhere by a human-interacting client. - Arguments: - value -- An integer value greater than or equal to 0. + :param int value: An integer value greater than or equal to 0. """ self._set_sub_text('priority', text=str(value)) def get_priority(self): """ Return the value of the element as an integer. + + :rtype: int """ p = self._get_sub_text('priority') if not p: @@ -166,13 +158,12 @@ class Presence(RootStanza): def reply(self, clear=True): """ - Set the appropriate presence reply type. + Create a new reply stanza from ``self``. Overrides StanzaBase.reply. - Arguments: - clear -- Indicates if the stanza contents should be removed - before replying. Defaults to True. + :param bool clear: Indicates if the stanza contents should be removed + before replying. Defaults to True. """ new_presence = StanzaBase.reply(self, clear) if self['type'] == 'unsubscribe': diff --git a/slixmpp/xmlstream/stanzabase.py b/slixmpp/xmlstream/stanzabase.py index 392fd55b..10c29782 100644 --- a/slixmpp/xmlstream/stanzabase.py +++ b/slixmpp/xmlstream/stanzabase.py @@ -1474,7 +1474,7 @@ class StanzaBase(ElementBase): Only type values contained in :attr:`types` are accepted. - :param string value: One of the values contained in :attr:`types` + :param str value: One of the values contained in :attr:`types` """ if value in self.types: self.xml.attrib['type'] = value @@ -1499,8 +1499,8 @@ class StanzaBase(ElementBase): def set_from(self, value): """Set the 'from' attribute of the stanza. - Arguments: - from -- A string or JID object representing the sender's JID. + :param from: A string or JID object representing the sender's JID. + :type from: str or :class:`.JID` """ return self._set_attr('from', str(value)) -- cgit v1.2.3