XEP-0045: Add stanza.NS* consts

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2020-05-29 17:27:51 +02:00
parent 03ee9bc4cc
commit 3b3eed544e
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -13,31 +13,36 @@ from slixmpp.xmlstream import ElementBase, ET, JID
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
NS = 'http://jabber.org/protocol/muc'
NS_USER = 'http://jabber.org/protocol/muc#user'
NS_ADMIN = 'http://jabber.org/protocol/muc#admin'
NS_OWNER = 'http://jabber.org/protocol/muc#owner'
class MUCPresence(ElementBase): class MUCPresence(ElementBase):
name = 'x' name = 'x'
namespace = 'http://jabber.org/protocol/muc#user' namespace = NS_USER
plugin_attrib = 'muc' plugin_attrib = 'muc'
interfaces = {'affiliation', 'role', 'jid', 'nick', 'room'} interfaces = {'affiliation', 'role', 'jid', 'nick', 'room'}
affiliations = {'', } affiliations = {'', }
roles = {'', } roles = {'', }
def get_item_attr(self, attr, default): def get_item_attr(self, attr, default):
item = self.xml.find('{http://jabber.org/protocol/muc#user}item') item = self.xml.find('{{{NS_USER}}}item')
if item is None: if item is None:
return default return default
return item.get(attr) return item.get(attr)
def set_item_attr(self, attr, value): def set_item_attr(self, attr, value):
item = self.xml.find('{http://jabber.org/protocol/muc#user}item') item = self.xml.find(f'{{{NS_USER}}}item')
if item is None: if item is None:
item = ET.Element('{http://jabber.org/protocol/muc#user}item') item = ET.Element(f'{{{NS_USER}}}item')
self.xml.append(item) self.xml.append(item)
item.attrib[attr] = value item.attrib[attr] = value
return item return item
def del_item_attr(self, attr): def del_item_attr(self, attr):
item = self.xml.find('{http://jabber.org/protocol/muc#user}item') item = self.xml.find('{{{NS_USER}}}item')
if item is not None and attr in item.attrib: if item is not None and attr in item.attrib:
del item.attrib[attr] del item.attrib[attr]