core: fix wrong calls to addElement.

This commit is contained in:
Goffi 2025-10-29 12:12:25 +01:00
commit 9fd3e33425
5 changed files with 12 additions and 15 deletions

View file

@ -55,7 +55,7 @@ class XEP_0049(object):
client = self.host.get_client(profile_key)
# XXX: feature announcement in disco#info is not mandatory in XEP-0049, so we have to try to use private XML, and react according to the answer
iq_elt = compat.IQ(client.xmlstream)
query_elt = iq_elt.addElement("query", XEP_0049.NS_PRIVATE)
query_elt = iq_elt.addElement((XEP_0049.NS_PRIVATE, "query"))
query_elt.addChild(element)
return iq_elt.send()
@ -70,8 +70,8 @@ class XEP_0049(object):
client = self.host.get_client(profile_key)
# XXX: see private_xml_store note about feature checking
iq_elt = compat.IQ(client.xmlstream, "get")
query_elt = iq_elt.addElement("query", XEP_0049.NS_PRIVATE)
query_elt.addElement(node_name, namespace)
query_elt = iq_elt.addElement((XEP_0049.NS_PRIVATE, "query"))
query_elt.addElement((namespace, node_name))
def get_cb(answer_iq_elt):
answer_query_elt = next(answer_iq_elt.elements(XEP_0049.NS_PRIVATE, "query"))

View file

@ -458,7 +458,7 @@ class AdHocCommandHandler(XMPPHandler):
result["type"] = "result"
result["id"] = iq_elt["id"]
result["to"] = iq_elt["from"]
command_elt = result.addElement("command", NS_COMMANDS)
command_elt = result.addElement((NS_COMMANDS, "command" ))
command_elt["sessionid"] = session_id
command_elt["node"] = self.command.node
command_elt["status"] = status
@ -723,7 +723,7 @@ class XEP_0050:
"""
iq_elt = client.IQ(timeout=timeout)
iq_elt["to"] = entity.full()
command_elt = iq_elt.addElement("command", NS_COMMANDS)
command_elt = iq_elt.addElement((NS_COMMANDS, "command"))
command_elt["node"] = node
command_elt["action"] = action
if session_id is not None:

View file

@ -229,7 +229,7 @@ class XEP_0054(object):
iq_elt = client.IQ("get")
iq_elt["from"] = client.jid.full()
iq_elt["to"] = entity_jid.full()
iq_elt.addElement("vCard", NS_VCARD)
iq_elt.addElement((NS_VCARD, "vCard"))
iq_ret_elt = await iq_elt.send(entity_jid.full())
try:
return next(iq_ret_elt.elements(NS_VCARD, "vCard"))

View file

@ -27,10 +27,7 @@ from wokkel import disco, iwokkel
from zope.interface import implementer
from twisted.words.protocols.jabber.jid import JID
try:
from twisted.words.protocols.xmlstream import XMPPHandler
except ImportError:
from wokkel.subprotocols import XMPPHandler
from twisted.words.protocols.jabber.xmlstream import XMPPHandler
from twisted.words.xish import domish
from twisted.internet import reactor
from twisted.internet import error as internet_error
@ -235,7 +232,7 @@ class XEP_0085(object):
try:
# message with a body always mean active state
next(domish.generateElementsNamed(message.elements(), name="body"))
message.addElement("active", NS_CHAT_STATES)
message.addElement((NS_CHAT_STATES, "active"))
# launch the chat state machine (init the timer)
if self._is_muc(to_jid, profile):
to_jid = to_jid.userhostJID()
@ -244,7 +241,7 @@ class XEP_0085(object):
if "chat_state" in mess_data["extra"]:
state = mess_data["extra"].pop("chat_state")
assert state in CHAT_STATES
message.addElement(state, NS_CHAT_STATES)
message.addElement((NS_CHAT_STATES, state))
return mess_data
post_xml_treatments.addCallback(treatment)
@ -404,7 +401,7 @@ class ChatStateMachine(object):
"extra": {},
}
client.generate_message_xml(mess_data)
mess_data["xml"].addElement(state, NS_CHAT_STATES)
mess_data["xml"].addElement((NS_CHAT_STATES, state))
client.send(mess_data["xml"])
self.state = state

View file

@ -206,14 +206,14 @@ class SearchItem(BaseModel):
for field, element_name in field_mappings.items():
value = getattr(self, field)
if value is not None:
elem = item.addElement(element_name, NS_SEARCH)
elem = item.addElement((NS_SEARCH, element_name))
elem.addContent(
str(value).lower() if isinstance(value, bool) else str(value)
)
if self.is_open is not None:
item.addElement(
("is-open", NS_SEARCH), content="true" if self.is_open else "false"
(NS_SEARCH, "is-open"), content="true" if self.is_open else "false"
)
return item