XEP-0045: Remove support for old-style {get,set,del}TitleCase methods.
This commit is contained in:
parent
3a9b45e4f2
commit
813b45aded
@ -63,13 +63,13 @@ has been established:
|
|||||||
def start(self, event):
|
def start(self, event):
|
||||||
self.get_roster()
|
self.get_roster()
|
||||||
self.send_presence()
|
self.send_presence()
|
||||||
self.plugin['xep_0045'].joinMUC(self.room,
|
self.plugin['xep_0045'].join_muc(self.room,
|
||||||
self.nick,
|
self.nick,
|
||||||
wait=True)
|
wait=True)
|
||||||
|
|
||||||
Note that as in :ref:`echobot`, we need to include send an initial presence and request
|
Note that as in :ref:`echobot`, we need to include send an initial presence and request
|
||||||
the roster. Next, we want to join the group chat, so we call the
|
the roster. Next, we want to join the group chat, so we call the
|
||||||
``joinMUC`` method of the MUC plugin.
|
``join_muc`` method of the MUC plugin.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
@ -67,11 +67,11 @@ class MUCBot(slixmpp.ClientXMPP):
|
|||||||
"""
|
"""
|
||||||
self.get_roster()
|
self.get_roster()
|
||||||
self.send_presence()
|
self.send_presence()
|
||||||
self.plugin['xep_0045'].joinMUC(self.room,
|
self.plugin['xep_0045'].join_muc(self.room,
|
||||||
self.nick,
|
self.nick,
|
||||||
# If a room password is needed, use:
|
# If a room password is needed, use:
|
||||||
# password=the_room_password,
|
# password=the_room_password,
|
||||||
wait=True)
|
wait=True)
|
||||||
|
|
||||||
def muc_message(self, msg):
|
def muc_message(self, msg):
|
||||||
"""
|
"""
|
||||||
|
@ -29,82 +29,82 @@ class MUCPresence(ElementBase):
|
|||||||
affiliations = set(('', ))
|
affiliations = set(('', ))
|
||||||
roles = set(('', ))
|
roles = set(('', ))
|
||||||
|
|
||||||
def getXMLItem(self):
|
def get_xml_item(self):
|
||||||
item = self.xml.find('{http://jabber.org/protocol/muc#user}item')
|
item = self.xml.find('{http://jabber.org/protocol/muc#user}item')
|
||||||
if item is None:
|
if item is None:
|
||||||
item = ET.Element('{http://jabber.org/protocol/muc#user}item')
|
item = ET.Element('{http://jabber.org/protocol/muc#user}item')
|
||||||
self.xml.append(item)
|
self.xml.append(item)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def getAffiliation(self):
|
def get_affiliation(self):
|
||||||
#TODO if no affilation, set it to the default and return default
|
#TODO if no affilation, set it to the default and return default
|
||||||
item = self.getXMLItem()
|
item = self.get_xml_item()
|
||||||
return item.get('affiliation', '')
|
return item.get('affiliation', '')
|
||||||
|
|
||||||
def setAffiliation(self, value):
|
def set_affiliation(self, value):
|
||||||
item = self.getXMLItem()
|
item = self.get_xml_item()
|
||||||
#TODO check for valid affiliation
|
#TODO check for valid affiliation
|
||||||
item.attrib['affiliation'] = value
|
item.attrib['affiliation'] = value
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def delAffiliation(self):
|
def del_affiliation(self):
|
||||||
item = self.getXMLItem()
|
item = self.get_xml_item()
|
||||||
#TODO set default affiliation
|
#TODO set default affiliation
|
||||||
if 'affiliation' in item.attrib: del item.attrib['affiliation']
|
if 'affiliation' in item.attrib: del item.attrib['affiliation']
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def getJid(self):
|
def get_jid(self):
|
||||||
item = self.getXMLItem()
|
item = self.get_xml_item()
|
||||||
return JID(item.get('jid', ''))
|
return JID(item.get('jid', ''))
|
||||||
|
|
||||||
def setJid(self, value):
|
def set_jid(self, value):
|
||||||
item = self.getXMLItem()
|
item = self.get_xml_item()
|
||||||
if not isinstance(value, str):
|
if not isinstance(value, str):
|
||||||
value = str(value)
|
value = str(value)
|
||||||
item.attrib['jid'] = value
|
item.attrib['jid'] = value
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def delJid(self):
|
def del_jid(self):
|
||||||
item = self.getXMLItem()
|
item = self.get_xml_item()
|
||||||
if 'jid' in item.attrib: del item.attrib['jid']
|
if 'jid' in item.attrib: del item.attrib['jid']
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def getRole(self):
|
def get_role(self):
|
||||||
item = self.getXMLItem()
|
item = self.get_xml_item()
|
||||||
#TODO get default role, set default role if none
|
#TODO get default role, set default role if none
|
||||||
return item.get('role', '')
|
return item.get('role', '')
|
||||||
|
|
||||||
def setRole(self, value):
|
def set_role(self, value):
|
||||||
item = self.getXMLItem()
|
item = self.get_xml_item()
|
||||||
#TODO check for valid role
|
#TODO check for valid role
|
||||||
item.attrib['role'] = value
|
item.attrib['role'] = value
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def delRole(self):
|
def del_role(self):
|
||||||
item = self.getXMLItem()
|
item = self.get_xml_item()
|
||||||
#TODO set default role
|
#TODO set default role
|
||||||
if 'role' in item.attrib: del item.attrib['role']
|
if 'role' in item.attrib: del item.attrib['role']
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def getNick(self):
|
def get_nick(self):
|
||||||
return self.parent()['from'].resource
|
return self.parent()['from'].resource
|
||||||
|
|
||||||
def getRoom(self):
|
def get_room(self):
|
||||||
return self.parent()['from'].bare
|
return self.parent()['from'].bare
|
||||||
|
|
||||||
def setNick(self, value):
|
def set_nick(self, value):
|
||||||
log.warning("Cannot set nick through mucpresence plugin.")
|
log.warning("Cannot set nick through mucpresence plugin.")
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def setRoom(self, value):
|
def set_room(self, value):
|
||||||
log.warning("Cannot set room through mucpresence plugin.")
|
log.warning("Cannot set room through mucpresence plugin.")
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def delNick(self):
|
def del_nick(self):
|
||||||
log.warning("Cannot delete nick through mucpresence plugin.")
|
log.warning("Cannot delete nick through mucpresence plugin.")
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def delRoom(self):
|
def del_room(self):
|
||||||
log.warning("Cannot delete room through mucpresence plugin.")
|
log.warning("Cannot delete room through mucpresence plugin.")
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ class XEP_0045(BasePlugin):
|
|||||||
|
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
self.rooms = {}
|
self.rooms = {}
|
||||||
self.ourNicks = {}
|
self.our_nicks = {}
|
||||||
self.xep = '0045'
|
self.xep = '0045'
|
||||||
# load MUC support in presence stanzas
|
# load MUC support in presence stanzas
|
||||||
register_stanza_plugin(Presence, MUCPresence)
|
register_stanza_plugin(Presence, MUCPresence)
|
||||||
@ -201,22 +201,22 @@ class XEP_0045(BasePlugin):
|
|||||||
"""
|
"""
|
||||||
self.xmpp.event('groupchat_subject', msg)
|
self.xmpp.event('groupchat_subject', msg)
|
||||||
|
|
||||||
def jidInRoom(self, room, jid):
|
def jid_in_room(self, room, jid):
|
||||||
for nick in self.rooms[room]:
|
for nick in self.rooms[room]:
|
||||||
entry = self.rooms[room][nick]
|
entry = self.rooms[room][nick]
|
||||||
if entry is not None and entry['jid'].full == jid:
|
if entry is not None and entry['jid'].full == jid:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getNick(self, room, jid):
|
def get_nick(self, room, jid):
|
||||||
for nick in self.rooms[room]:
|
for nick in self.rooms[room]:
|
||||||
entry = self.rooms[room][nick]
|
entry = self.rooms[room][nick]
|
||||||
if entry is not None and entry['jid'].full == jid:
|
if entry is not None and entry['jid'].full == jid:
|
||||||
return nick
|
return nick
|
||||||
|
|
||||||
def configureRoom(self, room, form=None, ifrom=None):
|
def configure_room(self, room, form=None, ifrom=None):
|
||||||
if form is None:
|
if form is None:
|
||||||
form = self.getRoomConfig(room, ifrom=ifrom)
|
form = self.get_room_config(room, ifrom=ifrom)
|
||||||
iq = self.xmpp.make_iq_set()
|
iq = self.xmpp.make_iq_set()
|
||||||
iq['to'] = room
|
iq['to'] = room
|
||||||
if ifrom is not None:
|
if ifrom is not None:
|
||||||
@ -234,7 +234,7 @@ class XEP_0045(BasePlugin):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def joinMUC(self, room, nick, maxhistory="0", password='', wait=False, pstatus=None, pshow=None, pfrom=None):
|
def join_muc(self, room, nick, maxhistory="0", password='', wait=False, pstatus=None, pshow=None, pfrom=None):
|
||||||
""" Join the specified room, requesting 'maxhistory' lines of history.
|
""" Join the specified room, requesting 'maxhistory' lines of history.
|
||||||
"""
|
"""
|
||||||
stanza = self.xmpp.make_presence(pto="%s/%s" % (room, nick), pstatus=pstatus, pshow=pshow, pfrom=pfrom)
|
stanza = self.xmpp.make_presence(pto="%s/%s" % (room, nick), pstatus=pstatus, pshow=pshow, pfrom=pfrom)
|
||||||
@ -258,7 +258,7 @@ class XEP_0045(BasePlugin):
|
|||||||
expect = ET.Element("{%s}presence" % self.xmpp.default_ns, {'from':"%s/%s" % (room, nick)})
|
expect = ET.Element("{%s}presence" % self.xmpp.default_ns, {'from':"%s/%s" % (room, nick)})
|
||||||
self.xmpp.send(stanza, expect)
|
self.xmpp.send(stanza, expect)
|
||||||
self.rooms[room] = {}
|
self.rooms[room] = {}
|
||||||
self.ourNicks[room] = nick
|
self.our_nicks[room] = nick
|
||||||
|
|
||||||
def destroy(self, room, reason='', altroom = '', ifrom=None):
|
def destroy(self, room, reason='', altroom = '', ifrom=None):
|
||||||
iq = self.xmpp.make_iq_set()
|
iq = self.xmpp.make_iq_set()
|
||||||
@ -283,7 +283,7 @@ class XEP_0045(BasePlugin):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setAffiliation(self, room, jid=None, nick=None, affiliation='member', ifrom=None):
|
def set_affiliation(self, room, jid=None, nick=None, affiliation='member', ifrom=None):
|
||||||
""" Change room affiliation."""
|
""" Change room affiliation."""
|
||||||
if affiliation not in ('outcast', 'member', 'admin', 'owner', 'none'):
|
if affiliation not in ('outcast', 'member', 'admin', 'owner', 'none'):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
@ -305,7 +305,7 @@ class XEP_0045(BasePlugin):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setRole(self, room, nick, role):
|
def set_role(self, room, nick, role):
|
||||||
""" Change role property of a nick in a room.
|
""" Change role property of a nick in a room.
|
||||||
Typically, roles are temporary (they last only as long as you are in the
|
Typically, roles are temporary (they last only as long as you are in the
|
||||||
room), whereas affiliations are permanent (they last across groupchat
|
room), whereas affiliations are permanent (they last across groupchat
|
||||||
@ -337,7 +337,7 @@ class XEP_0045(BasePlugin):
|
|||||||
msg.append(x)
|
msg.append(x)
|
||||||
self.xmpp.send(msg)
|
self.xmpp.send(msg)
|
||||||
|
|
||||||
def leaveMUC(self, room, nick, msg='', pfrom=None):
|
def leave_muc(self, room, nick, msg='', pfrom=None):
|
||||||
""" Leave the specified room.
|
""" Leave the specified room.
|
||||||
"""
|
"""
|
||||||
if msg:
|
if msg:
|
||||||
@ -346,7 +346,7 @@ class XEP_0045(BasePlugin):
|
|||||||
self.xmpp.send_presence(pshow='unavailable', pto="%s/%s" % (room, nick), pfrom=pfrom)
|
self.xmpp.send_presence(pshow='unavailable', pto="%s/%s" % (room, nick), pfrom=pfrom)
|
||||||
del self.rooms[room]
|
del self.rooms[room]
|
||||||
|
|
||||||
def getRoomConfig(self, room, ifrom=''):
|
def get_room_config(self, room, ifrom=''):
|
||||||
iq = self.xmpp.make_iq_get('http://jabber.org/protocol/muc#owner')
|
iq = self.xmpp.make_iq_get('http://jabber.org/protocol/muc#owner')
|
||||||
iq['to'] = room
|
iq['to'] = room
|
||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
@ -362,7 +362,7 @@ class XEP_0045(BasePlugin):
|
|||||||
raise ValueError
|
raise ValueError
|
||||||
return self.xmpp.plugin['xep_0004'].build_form(form)
|
return self.xmpp.plugin['xep_0004'].build_form(form)
|
||||||
|
|
||||||
def cancelConfig(self, room, ifrom=None):
|
def cancel_config(self, room, ifrom=None):
|
||||||
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
||||||
x = ET.Element('{jabber:x:data}x', type='cancel')
|
x = ET.Element('{jabber:x:data}x', type='cancel')
|
||||||
query.append(x)
|
query.append(x)
|
||||||
@ -371,7 +371,7 @@ class XEP_0045(BasePlugin):
|
|||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
iq.send()
|
iq.send()
|
||||||
|
|
||||||
def setRoomConfig(self, room, config, ifrom=''):
|
def set_room_config(self, room, config, ifrom=''):
|
||||||
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
||||||
config['type'] = 'submit'
|
config['type'] = 'submit'
|
||||||
query.append(config)
|
query.append(config)
|
||||||
@ -380,31 +380,31 @@ class XEP_0045(BasePlugin):
|
|||||||
iq['from'] = ifrom
|
iq['from'] = ifrom
|
||||||
iq.send()
|
iq.send()
|
||||||
|
|
||||||
def getJoinedRooms(self):
|
def get_joined_rooms(self):
|
||||||
return self.rooms.keys()
|
return self.rooms.keys()
|
||||||
|
|
||||||
def getOurJidInRoom(self, roomJid):
|
def get_our_jid_in_room(self, room_jid):
|
||||||
""" Return the jid we're using in a room.
|
""" Return the jid we're using in a room.
|
||||||
"""
|
"""
|
||||||
return "%s/%s" % (roomJid, self.ourNicks[roomJid])
|
return "%s/%s" % (room_jid, self.our_nicks[room_jid])
|
||||||
|
|
||||||
def getJidProperty(self, room, nick, jidProperty):
|
def get_jid_property(self, room, nick, jid_property):
|
||||||
""" Get the property of a nick in a room, such as its 'jid' or 'affiliation'
|
""" Get the property of a nick in a room, such as its 'jid' or 'affiliation'
|
||||||
If not found, return None.
|
If not found, return None.
|
||||||
"""
|
"""
|
||||||
if room in self.rooms and nick in self.rooms[room] and jidProperty in self.rooms[room][nick]:
|
if room in self.rooms and nick in self.rooms[room] and jid_property in self.rooms[room][nick]:
|
||||||
return self.rooms[room][nick][jidProperty]
|
return self.rooms[room][nick][jid_property]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getRoster(self, room):
|
def get_roster(self, room):
|
||||||
""" Get the list of nicks in a room.
|
""" Get the list of nicks in a room.
|
||||||
"""
|
"""
|
||||||
if room not in self.rooms.keys():
|
if room not in self.rooms.keys():
|
||||||
return None
|
return None
|
||||||
return self.rooms[room].keys()
|
return self.rooms[room].keys()
|
||||||
|
|
||||||
def getUsersByAffiliation(cls, room, affiliation='member', ifrom=None):
|
def get_users_by_affiliation(cls, room, affiliation='member', ifrom=None):
|
||||||
if affiliation not in ('outcast', 'member', 'admin', 'owner', 'none'):
|
if affiliation not in ('outcast', 'member', 'admin', 'owner', 'none'):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
query = ET.Element('{http://jabber.org/protocol/muc#admin}query')
|
query = ET.Element('{http://jabber.org/protocol/muc#admin}query')
|
||||||
@ -415,5 +415,4 @@ class XEP_0045(BasePlugin):
|
|||||||
return iq.send()
|
return iq.send()
|
||||||
|
|
||||||
|
|
||||||
xep_0045 = XEP_0045
|
|
||||||
register_plugin(XEP_0045)
|
register_plugin(XEP_0045)
|
||||||
|
@ -59,7 +59,7 @@ class XEP_0048(BasePlugin):
|
|||||||
for conf in bookmarks['conferences']:
|
for conf in bookmarks['conferences']:
|
||||||
if conf['autojoin']:
|
if conf['autojoin']:
|
||||||
log.debug('Auto joining %s as %s', conf['jid'], conf['nick'])
|
log.debug('Auto joining %s as %s', conf['jid'], conf['nick'])
|
||||||
self.xmpp['xep_0045'].joinMUC(conf['jid'], conf['nick'],
|
self.xmpp['xep_0045'].join_muc(conf['jid'], conf['nick'],
|
||||||
password=conf['password'])
|
password=conf['password'])
|
||||||
|
|
||||||
def set_bookmarks(self, bookmarks, method=None, **iqargs):
|
def set_bookmarks(self, bookmarks, method=None, **iqargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user