diff options
author | Nathan Fritz <fritzy@netflint.net> | 2009-12-15 04:31:46 +0000 |
---|---|---|
committer | Nathan Fritz <fritzy@netflint.net> | 2009-12-15 04:31:46 +0000 |
commit | ca044a4934bc6373988a1b442da3673b70357317 (patch) | |
tree | 11275ef8bbc21b68bbd8305f69654ff2442a42db /sleekxmpp | |
parent | 8854509ccdbc1f9ea74e1eb00f3af098f2a3b6b6 (diff) | |
download | slixmpp-ca044a4934bc6373988a1b442da3673b70357317.tar.gz slixmpp-ca044a4934bc6373988a1b442da3673b70357317.tar.bz2 slixmpp-ca044a4934bc6373988a1b442da3673b70357317.tar.xz slixmpp-ca044a4934bc6373988a1b442da3673b70357317.zip |
makeMessage and makePresence now use new stanza classes
fixed component usage of stanzas
Diffstat (limited to 'sleekxmpp')
-rw-r--r-- | sleekxmpp/basexmpp.py | 67 | ||||
-rwxr-xr-x | sleekxmpp/componentxmpp.py | 2 |
2 files changed, 14 insertions, 55 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 2288e8e7..2049206b 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -187,63 +187,22 @@ class basexmpp(object): with self.lock: self.event_handlers[name].pop(self.event_handlers[name].index(handler)) - def makeMessage(self, mto, mbody='', msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None): - message = ET.Element('{%s}message' % self.default_ns) - if mfrom is None: - message.attrib['from'] = self.fulljid - else: - message.attrib['from'] = mfrom - message.attrib['to'] = mto - if not mtype: - mtype='chat' - message.attrib['type'] = mtype - if mtype == 'none': - del message.attrib['type'] - if mbody: - body = ET.Element('body') - body.text = mbody - message.append(body) - if mhtml : - html = ET.Element('{http://jabber.org/protocol/xhtml-im}html') - html_body = ET.XML('<body xmlns="http://www.w3.org/1999/xhtml">' + mhtml + '</body>') - html.append(html_body) - message.append(html) - if msubject: - subject = ET.Element('subject') - subject.text = msubject - message.append(subject) - if mnick: - print("generating nick") - nick = ET.Element("{http://jabber.org/protocol/nick}nick") - nick.text = mnick - message.append(nick) + def makeMessage(self, mto, mbody=None, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None): + message = self.Message(sto=mto, stype=mtype, sfrom=mfrom) + message['body'] = mbody + message['subject'] = msubject + message['nick'] = mnick + message['html'] = mhtml return message def makePresence(self, pshow=None, pstatus=None, ppriority=None, pto=None, ptype=None, pfrom=None): - if pshow == 'unavailable': - pshow = None - ptype = 'unavailable' - presence = ET.Element('{%s}presence' % self.default_ns) - if ptype: - presence.attrib['type'] = ptype - if pshow: - show = ET.Element('show') - show.text = pshow - presence.append(show) - if pstatus: - status = ET.Element('status') - status.text = pstatus - presence.append(status) - if ppriority: - priority = ET.Element('priority') - priority.text = str(ppriority) - presence.append(priority) - if pto: - presence.attrib['to'] = pto - if pfrom is None: - presence.attrib['from'] = self.fulljid - else: - presence.attrib['from'] = pfrom + presence = self.Presence(stype=ptype, sfrom=pfrom, sto=pto) + if pshow is not None: + presence['type'] = pshow + if pfrom is None: #maybe this should be done in stanzabase + presence['from'] = self.fulljid + presence['priority'] = ppriority + presence['status'] = pstatus return presence def sendMessage(self, mto, mbody, msubject=None, mtype=None, mhtml=None, mfrom=None, mnick=None): diff --git a/sleekxmpp/componentxmpp.py b/sleekxmpp/componentxmpp.py index 446f3d85..e6920897 100755 --- a/sleekxmpp/componentxmpp.py +++ b/sleekxmpp/componentxmpp.py @@ -100,7 +100,7 @@ class ComponentXMPP(basexmpp, XMLStream): sid = xml.get('id', '') handshake = ET.Element('{jabber:component:accept}handshake') handshake.text = hashlib.sha1(bytes("%s%s" % (sid, self.secret), 'utf-8')).hexdigest().lower() - self.send(handshake) + self.sendXML(handshake) def _handleHandshake(self, xml): self.event("session_start") |