From 181aea737d5bce9479795b58c29b5a92da3bd48b Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 5 Jun 2012 16:54:26 -0700 Subject: Add initial support for xml:lang for streams and stanza plugins. Remaining items are suitable default actions for language supporting interfaces. --- sleekxmpp/basexmpp.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sleekxmpp/basexmpp.py') diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 43ea6063..4f48f809 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -31,6 +31,7 @@ from sleekxmpp.xmlstream import XMLStream, JID from sleekxmpp.xmlstream import ET, register_stanza_plugin from sleekxmpp.xmlstream.matcher import MatchXPath from sleekxmpp.xmlstream.handler import Callback +from sleekxmpp.xmlstream.stanzabase import XML_NS from sleekxmpp.features import * from sleekxmpp.plugins import PluginManager, register_plugin, load_plugin @@ -180,6 +181,8 @@ class BaseXMPP(XMLStream): :param xml: The incoming stream's root element. """ self.stream_id = xml.get('id', '') + self.stream_version = xml.get('version', '') + self.peer_default_lang = xml.get('{%s}lang' % XML_NS, None) def process(self, *args, **kwargs): """Initialize plugins and begin processing the XML stream. @@ -272,7 +275,9 @@ class BaseXMPP(XMLStream): def Message(self, *args, **kwargs): """Create a Message stanza associated with this stream.""" - return Message(self, *args, **kwargs) + msg = Message(self, *args, **kwargs) + msg['lang'] = self.default_lang + return msg def Iq(self, *args, **kwargs): """Create an Iq stanza associated with this stream.""" @@ -280,7 +285,9 @@ class BaseXMPP(XMLStream): def Presence(self, *args, **kwargs): """Create a Presence stanza associated with this stream.""" - return Presence(self, *args, **kwargs) + pres = Presence(self, *args, **kwargs) + pres['lang'] = self.default_lang + return pres def make_iq(self, id=0, ifrom=None, ito=None, itype=None, iquery=None): """Create a new Iq stanza with a given Id and from JID. -- cgit v1.2.3 From ff6fc44215c07ef112c59dec32ed753cd30a460c Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Mon, 18 Jun 2012 17:28:58 -0700 Subject: Simplify tracking last sent presence using outgoing filters. --- sleekxmpp/basexmpp.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'sleekxmpp/basexmpp.py') diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 4f48f809..099b6dd0 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -536,18 +536,8 @@ class BaseXMPP(XMLStream): :param pfrom: The sender of the presence. :param pnick: Optional nickname of the presence's sender. """ - # Python2.6 chokes on Unicode strings for dict keys. - args = {str('pto'): pto, - str('ptype'): ptype, - str('pshow'): pshow, - str('pstatus'): pstatus, - str('ppriority'): ppriority, - str('pnick'): pnick} - - if self.is_component: - self.roster[pfrom].send_presence(**args) - else: - self.client_roster.send_presence(**args) + self.make_presence(pshow, pstatus, ppriority, pto, + ptype, pfrom, pnick).send() def send_presence_subscription(self, pto, pfrom=None, ptype='subscribe', pnick=None): -- cgit v1.2.3 From f7a74d960edb3ced00423c081ec74e9e91f3aea2 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 19 Jun 2012 00:06:31 -0700 Subject: Simplify send_presence_subscription() --- sleekxmpp/basexmpp.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'sleekxmpp/basexmpp.py') diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 099b6dd0..576cfe87 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -551,14 +551,10 @@ class BaseXMPP(XMLStream): :param ptype: The type of presence, such as ``'subscribe'``. :param pnick: Optional nickname of the presence's sender. """ - presence = self.makePresence(ptype=ptype, - pfrom=pfrom, - pto=self.getjidbare(pto)) - if pnick: - nick = ET.Element('{http://jabber.org/protocol/nick}nick') - nick.text = pnick - presence.append(nick) - presence.send() + self.make_presence(ptype=ptype, + pfrom=pfrom, + pto=JID(pto).bare, + pnick=pnick).send() @property def jid(self): -- cgit v1.2.3 From d92aa05b5c18806ab5addc947eeedaaf4d51500e Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 19 Jun 2012 01:29:48 -0700 Subject: PEP8 formatting updates. --- sleekxmpp/basexmpp.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'sleekxmpp/basexmpp.py') diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 576cfe87..aae80168 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -67,7 +67,7 @@ class BaseXMPP(XMLStream): #: An identifier for the stream as given by the server. self.stream_id = None - #: The JabberID (JID) used by this connection. + #: The JabberID (JID) used by this connection. self.boundjid = JID(jid) self._expected_server_name = self.boundjid.host @@ -103,7 +103,7 @@ class BaseXMPP(XMLStream): #: The API registry is a way to process callbacks based on #: JID+node combinations. Each callback in the registry is #: marked with: - #: + #: #: - An API name, e.g. xep_0030 #: - The name of an action, e.g. get_info #: - The JID that will be affected @@ -202,7 +202,7 @@ class BaseXMPP(XMLStream): Defaults to ``True``. This does **not** mean that no threads are used at all if ``threaded=False``. - Regardless of these threading options, these threads will + Regardless of these threading options, these threads will always exist: - The event queue processor @@ -294,11 +294,11 @@ class BaseXMPP(XMLStream): :param id: An ideally unique ID value for this stanza thread. Defaults to 0. - :param ifrom: The from :class:`~sleekxmpp.xmlstream.jid.JID` + :param ifrom: The from :class:`~sleekxmpp.xmlstream.jid.JID` to use for this stanza. :param ito: The destination :class:`~sleekxmpp.xmlstream.jid.JID` for this stanza. - :param itype: The :class:`~sleekxmpp.stanza.iq.Iq`'s type, + :param itype: The :class:`~sleekxmpp.stanza.iq.Iq`'s type, one of: ``'get'``, ``'set'``, ``'result'``, or ``'error'``. :param iquery: Optional namespace for adding a query element. @@ -336,7 +336,7 @@ class BaseXMPP(XMLStream): def make_iq_result(self, id=None, ito=None, ifrom=None, iq=None): """ - Create an :class:`~sleekxmpp.stanza.iq.Iq` stanza of type + Create an :class:`~sleekxmpp.stanza.iq.Iq` stanza of type ``'result'`` with the given ID value. :param id: An ideally unique ID value. May use :meth:`new_id()`. @@ -366,10 +366,10 @@ class BaseXMPP(XMLStream): Optionally, a substanza may be given to use as the stanza's payload. - :param sub: Either an + :param sub: Either an :class:`~sleekxmpp.xmlstream.stanzabase.ElementBase` stanza object or an - :class:`~xml.etree.ElementTree.Element` XML object + :class:`~xml.etree.ElementTree.Element` XML object to use as the :class:`~sleekxmpp.stanza.iq.Iq`'s payload. :param ito: The destination :class:`~sleekxmpp.xmlstream.jid.JID` for this stanza. @@ -396,9 +396,9 @@ class BaseXMPP(XMLStream): Create an :class:`~sleekxmpp.stanza.iq.Iq` stanza of type ``'error'``. :param id: An ideally unique ID value. May use :meth:`new_id()`. - :param type: The type of the error, such as ``'cancel'`` or + :param type: The type of the error, such as ``'cancel'`` or ``'modify'``. Defaults to ``'cancel'``. - :param condition: The error condition. Defaults to + :param condition: The error condition. Defaults to ``'feature-not-implemented'``. :param text: A message describing the cause of the error. :param ito: The destination :class:`~sleekxmpp.xmlstream.jid.JID` @@ -422,7 +422,7 @@ class BaseXMPP(XMLStream): def make_iq_query(self, iq=None, xmlns='', ito=None, ifrom=None): """ - Create or modify an :class:`~sleekxmpp.stanza.iq.Iq` stanza + Create or modify an :class:`~sleekxmpp.stanza.iq.Iq` stanza to use the given query namespace. :param iq: Optionally use an existing stanza instead @@ -455,7 +455,7 @@ class BaseXMPP(XMLStream): def make_message(self, mto, mbody=None, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None): """ - Create and initialize a new + Create and initialize a new :class:`~sleekxmpp.stanza.message.Message` stanza. :param mto: The recipient of the message. @@ -481,7 +481,7 @@ class BaseXMPP(XMLStream): def make_presence(self, pshow=None, pstatus=None, ppriority=None, pto=None, ptype=None, pfrom=None, pnick=None): """ - Create and initialize a new + Create and initialize a new :class:`~sleekxmpp.stanza.presence.Presence` stanza. :param pshow: The presence's show value. @@ -505,7 +505,7 @@ class BaseXMPP(XMLStream): def send_message(self, mto, mbody, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None): """ - Create, initialize, and send a new + Create, initialize, and send a new :class:`~sleekxmpp.stanza.message.Message` stanza. :param mto: The recipient of the message. @@ -525,7 +525,7 @@ class BaseXMPP(XMLStream): def send_presence(self, pshow=None, pstatus=None, ppriority=None, pto=None, pfrom=None, ptype=None, pnick=None): """ - Create, initialize, and send a new + Create, initialize, and send a new :class:`~sleekxmpp.stanza.presence.Presence` stanza. :param pshow: The presence's show value. @@ -536,13 +536,13 @@ class BaseXMPP(XMLStream): :param pfrom: The sender of the presence. :param pnick: Optional nickname of the presence's sender. """ - self.make_presence(pshow, pstatus, ppriority, pto, + self.make_presence(pshow, pstatus, ppriority, pto, ptype, pfrom, pnick).send() def send_presence_subscription(self, pto, pfrom=None, ptype='subscribe', pnick=None): """ - Create, initialize, and send a new + Create, initialize, and send a new :class:`~sleekxmpp.stanza.presence.Presence` stanza of type ``'subscribe'``. @@ -743,7 +743,7 @@ class BaseXMPP(XMLStream): return def exception(self, exception): - """Process any uncaught exceptions, notably + """Process any uncaught exceptions, notably :class:`~sleekxmpp.exceptions.IqError` and :class:`~sleekxmpp.exceptions.IqTimeout` exceptions. -- cgit v1.2.3