Esempio n. 1
0
 def test_message_full(self):
     msg = Message(
             from_jid = JID("[email protected]/res"),
             to_jid = JID("*****@*****.**"),
             stanza_type = "normal",
             stanza_id = u"1",
             subject = u"Subject",
             body = u"The body",
             thread = u"thread-id")
     payload = ElementTree.Element(
                         "{http://pyxmpp.jajcus.net/xmlns/test}payload")
     ElementTree.SubElement(payload, 
                             "{http://pyxmpp.jajcus.net/xmlns/test}abc")
     payload = XMLPayload(payload)
     msg.add_payload(payload)
     self.check_message_full(msg)
     xml = msg.as_xml()
     self.check_message_full(Message(xml))
Esempio n. 2
0
 def test_message_full(self):
     msg = Message(
             from_jid = JID("[email protected]/res"),
             to_jid = JID("*****@*****.**"),
             stanza_type = "normal",
             stanza_id = u"1",
             subject = u"Subject",
             body = u"The body",
             thread = u"thread-id")
     payload = ElementTree.Element(
                         "{http://pyxmpp.jajcus.net/xmlns/test}payload")
     ElementTree.SubElement(payload,
                             "{http://pyxmpp.jajcus.net/xmlns/test}abc")
     payload = XMLPayload(payload)
     msg.add_payload(payload)
     self.check_message_full(msg)
     xml = msg.as_xml()
     self.check_message_full(Message(xml))
Esempio n. 3
0
def outgoing_message(stanza):
	"""
	Adapt an outgoint Message stanza. Either properly encode the
	message contents, or convert it to a typing notification,
	if no body is included.
	"""

	logger.debug('outgoing message, body=%r', stanza.body)

	if stanza.body:
		body = tlen_encode(stanza.body)
		# This strips all additional XML tags, like html part etc.
		stanza = Message(stanza_type = stanza.stanza_type,
				from_jid = stanza.from_jid, to_jid = stanza.to_jid,
				subject = stanza.subject, body = body,
				thread = stanza.thread)
		return stanza

	# If the message had no body, assume it's a typing notification.

	xml = stanza.as_xml()

	for chatstate in xml:
		if chatstate.tag.startswith(const.CHATSTATES_NS_QNP):
			break
	# If no chatstate found, give up and send unmodified stanza
	else:
		return stanza

	logger.debug('chatstate=%s', chatstate)

	# Need to add a namespace to keep Stanza happy
	# For XML format, see docstring for incoming_chatstate()
	m = ElementTree.Element('{jabber:client}m')
	m.set('to', stanza.to_jid.as_unicode())

	if chatstate.tag.endswith('composing'):
		m.set('tp', 't')
	else:
		m.set('tp', 'u')

	return Stanza(m)
Esempio n. 4
0
 def test_message_empty(self):
     msg = Message()
     self.check_message_empty(msg)
     xml = msg.as_xml()
     self.check_message_empty(Message(xml))
Esempio n. 5
0
 def test_message_empty(self):
     msg = Message()
     self.check_message_empty(msg)
     xml = msg.as_xml()
     self.check_message_empty(Message(xml))