From b0a2a305028bf284fc5dcf7e1a696d85787f128f Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Mon, 8 Nov 2010 00:59:14 +0100 Subject: Add the sleekxmpp library (will be added as a submodule later) --- sleekxmpp/stanza/nick.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 sleekxmpp/stanza/nick.py (limited to 'sleekxmpp/stanza/nick.py') diff --git a/sleekxmpp/stanza/nick.py b/sleekxmpp/stanza/nick.py new file mode 100644 index 0000000..a9243d1 --- /dev/null +++ b/sleekxmpp/stanza/nick.py @@ -0,0 +1,89 @@ +""" + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2010 Nathanael C. Fritz + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.stanza import Message, Presence +from sleekxmpp.xmlstream import ElementBase, ET, register_stanza_plugin + + +class Nick(ElementBase): + + """ + XEP-0172: User Nickname allows the addition of a element + in several stanza types, including and stanzas. + + The nickname contained in a should be the global, friendly or + informal name chosen by the owner of a bare JID. The element + may be included when establishing communications with new entities, + such as normal XMPP users or MUC services. + + The nickname contained in a element will not necessarily be + the same as the nickname used in a MUC. + + Example stanzas: + + The User + ... + + + + The User + + + Stanza Interface: + nick -- A global, friendly or informal name chosen by a user. + + Methods: + setup -- Overrides ElementBase.setup. + get_nick -- Return the nickname in the element. + set_nick -- Add a element with the given nickname. + del_nick -- Remove the element. + """ + + namespace = 'http://jabber.org/nick/nick' + name = 'nick' + plugin_attrib = name + interfaces = set(('nick',)) + + def setup(self, xml=None): + """ + Populate the stanza object using an optional XML object. + + Overrides StanzaBase.setup. + + Arguments: + xml -- Use an existing XML object for the stanza's values. + """ + # To comply with PEP8, method names now use underscores. + # Deprecated method names are re-mapped for backwards compatibility. + self.setNick = self.set_nick + self.getNick = self.get_nick + self.delNick = self.del_nick + + return ElementBase.setup(self, xml) + + def set_nick(self, nick): + """ + Add a element with the given nickname. + + Arguments: + nick -- A human readable, informal name. + """ + self.xml.text = nick + + def get_nick(self): + """Return the nickname in the element.""" + return self.xml.text + + def del_nick(self): + """Remove the element.""" + if self.parent is not None: + self.parent().xml.remove(self.xml) + + +register_stanza_plugin(Message, Nick) +register_stanza_plugin(Presence, Nick) -- cgit v1.2.3-70-g09d2