Commit 75584d7a authored by Lance Stout's avatar Lance Stout

Remap old method names in a better way.

This should prevent some reference cycles that will cause garbage
collection issues.
parent e0f9025e
......@@ -90,20 +90,6 @@ class BaseXMPP(XMLStream):
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.registerPlugin = self.register_plugin
self.makeIq = self.make_iq
self.makeIqGet = self.make_iq_get
self.makeIqResult = self.make_iq_result
self.makeIqSet = self.make_iq_set
self.makeIqError = self.make_iq_error
self.makeIqQuery = self.make_iq_query
self.makeQueryRoster = self.make_query_roster
self.makeMessage = self.make_message
self.makePresence = self.make_presence
self.sendMessage = self.send_message
self.sendPresence = self.send_presence
self.sendPresenceSubscription = self.send_presence_subscription
self.default_ns = default_ns
self.stream_ns = 'http://etherx.jabber.org/streams'
......@@ -701,3 +687,19 @@ class BaseXMPP(XMLStream):
# Restore the old, lowercased name for backwards compatibility.
basexmpp = BaseXMPP
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
BaseXMPP.registerPlugin = BaseXMPP.register_plugin
BaseXMPP.makeIq = BaseXMPP.make_iq
BaseXMPP.makeIqGet = BaseXMPP.make_iq_get
BaseXMPP.makeIqResult = BaseXMPP.make_iq_result
BaseXMPP.makeIqSet = BaseXMPP.make_iq_set
BaseXMPP.makeIqError = BaseXMPP.make_iq_error
BaseXMPP.makeIqQuery = BaseXMPP.make_iq_query
BaseXMPP.makeQueryRoster = BaseXMPP.make_query_roster
BaseXMPP.makeMessage = BaseXMPP.make_message
BaseXMPP.makePresence = BaseXMPP.make_presence
BaseXMPP.sendMessage = BaseXMPP.send_message
BaseXMPP.sendPresence = BaseXMPP.send_presence
BaseXMPP.sendPresenceSubscription = BaseXMPP.send_presence_subscription
......@@ -68,13 +68,6 @@ class ClientXMPP(BaseXMPP):
"""
BaseXMPP.__init__(self, 'jabber:client')
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.updateRoster = self.update_roster
self.delRosterItem = self.del_roster_item
self.getRoster = self.get_roster
self.registerFeature = self.register_feature
self.set_jid(jid)
self.password = password
self.escape_quotes = escape_quotes
......@@ -439,3 +432,11 @@ class ClientXMPP(BaseXMPP):
iq.reply()
iq.enable('roster')
iq.send()
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
ClientXMPP.updateRoster = ClientXMPP.update_roster
ClientXMPP.delRosterItem = ClientXMPP.del_roster_item
ClientXMPP.getRoster = ClientXMPP.get_roster
ClientXMPP.registerFeature = ClientXMPP.register_feature
......@@ -90,10 +90,6 @@ class xep_0030(base_plugin):
self.description = 'Service Discovery'
self.stanza = sleekxmpp.plugins.xep_0030.stanza
# Retain some backwards compatibility
self.getInfo = self.get_info
self.getItems = self.get_items
self.xmpp.register_handler(
Callback('Disco Info',
StanzaPath('iq/disco_info'),
......@@ -124,7 +120,8 @@ class xep_0030(base_plugin):
"""Handle cross-plugin dependencies."""
base_plugin.post_init(self)
if self.xmpp['xep_0059']:
register_stanza_plugin(DiscoItems, self.xmpp['xep_0059'].stanza.Set)
register_stanza_plugin(DiscoItems,
self.xmpp['xep_0059'].stanza.Set)
def set_node_handler(self, htype, jid=None, node=None, handler=None):
"""
......@@ -378,7 +375,8 @@ class xep_0030(base_plugin):
"""
self._run_node_handler('del_item', jid, node, kwargs)
def add_identity(self, category='', itype='', name='', node=None, jid=None, lang=None):
def add_identity(self, category='', itype='', name='',
node=None, jid=None, lang=None):
"""
Add a new identity to the given JID/node combination.
......@@ -607,3 +605,7 @@ class xep_0030(base_plugin):
info.add_feature(info.namespace)
return info
# Retain some backwards compatibility
xep_0030.getInfo = xep_0030.get_info
xep_0030.getItems = xep_0030.get_items
......@@ -262,4 +262,3 @@ class StaticDisco(object):
self.nodes[(jid, node)]['items'].del_item(
data.get('ijid', ''),
node=data.get('inode', None))
......@@ -54,9 +54,6 @@ class xep_0199(base_plugin):
self.xep = '0199'
self.stanza = stanza
# Backwards compatibility for names
self.sendPing = self.send_ping
self.keepalive = self.config.get('keepalive', True)
self.frequency = float(self.config.get('frequency', 300))
self.timeout = self.config.get('timeout', 30)
......@@ -160,3 +157,7 @@ class xep_0199(base_plugin):
log.debug("Pong: %s %f" % (jid, delay))
return delay
# Backwards compatibility for names
Ping.sendPing = Ping.send_ping
......@@ -77,15 +77,6 @@ class Error(ElementBase):
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.getCondition = self.get_condition
self.setCondition = self.set_condition
self.delCondition = self.del_condition
self.getText = self.get_text
self.setText = self.set_text
self.delText = self.del_text
if ElementBase.setup(self, xml):
#If we had to generate XML then set default values.
self['type'] = 'cancel'
......@@ -139,3 +130,13 @@ class Error(ElementBase):
"""Remove the <text> element."""
self._del_sub('{%s}text' % self.condition_ns)
return self
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Error.getCondition = Error.get_condition
Error.setCondition = Error.set_condition
Error.delCondition = Error.del_condition
Error.getText = Error.get_text
Error.setText = Error.set_text
Error.delText = Error.del_text
......@@ -46,23 +46,6 @@ class HTMLIM(ElementBase):
interfaces = set(('body',))
plugin_attrib = name
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides StanzaBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setBody = self.set_body
self.getBody = self.get_body
self.delBody = self.del_body
return ElementBase.setup(self, xml)
def set_body(self, html):
"""
Set the contents of the HTML body.
......@@ -95,3 +78,9 @@ class HTMLIM(ElementBase):
register_stanza_plugin(Message, HTMLIM)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
HTMLIM.setBody = HTMLIM.set_body
HTMLIM.getBody = HTMLIM.get_body
HTMLIM.delBody = HTMLIM.del_body
......@@ -75,13 +75,6 @@ class Iq(RootStanza):
Overrides StanzaBase.__init__.
"""
StanzaBase.__init__(self, *args, **kwargs)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setPayload = self.set_payload
self.getQuery = self.get_query
self.setQuery = self.set_query
self.delQuery = self.del_query
if self['id'] == '':
if self.stream is not None:
self['id'] = self.stream.getNewId()
......@@ -229,3 +222,11 @@ class Iq(RootStanza):
else:
StanzaBase._set_stanza_values(self, values)
return self
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Iq.setPayload = Iq.set_payload
Iq.getQuery = Iq.get_query
Iq.setQuery = Iq.set_query
Iq.delQuery = Iq.del_query
......@@ -63,27 +63,6 @@ class Message(RootStanza):
plugin_attrib = name
types = set((None, 'normal', 'chat', 'headline', 'error', 'groupchat'))
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides StanzaBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.getType = self.get_type
self.getMucroom = self.get_mucroom
self.setMucroom = self.set_mucroom
self.delMucroom = self.del_mucroom
self.getMucnick = self.get_mucnick
self.setMucnick = self.set_mucnick
self.delMucnick = self.del_mucnick
return StanzaBase.setup(self, xml)
def get_type(self):
"""
Return the message type.
......@@ -165,3 +144,14 @@ class Message(RootStanza):
def del_mucnick(self):
"""Dummy method to prevent deletion."""
pass
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Message.getType = Message.get_type
Message.getMucroom = Message.get_mucroom
Message.setMucroom = Message.set_mucroom
Message.delMucroom = Message.del_mucroom
Message.getMucnick = Message.get_mucnick
Message.setMucnick = Message.set_mucnick
Message.delMucnick = Message.del_mucnick
......@@ -49,23 +49,6 @@ class Nick(ElementBase):
plugin_attrib = name
interfaces = set(('nick',))
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides StanzaBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setNick = self.set_nick
self.getNick = self.get_nick
self.delNick = self.del_nick
return ElementBase.setup(self, xml)
def set_nick(self, nick):
"""
Add a <nick> element with the given nickname.
......@@ -87,3 +70,9 @@ class Nick(ElementBase):
register_stanza_plugin(Message, Nick)
register_stanza_plugin(Presence, Nick)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Nick.setNick = Nick.set_nick
Nick.getNick = Nick.get_nick
Nick.delNick = Nick.del_nick
......@@ -72,26 +72,6 @@ class Presence(RootStanza):
'subscribed', 'unsubscribe', 'unsubscribed'))
showtypes = set(('dnd', 'chat', 'xa', 'away'))
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides ElementBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setShow = self.set_show
self.getType = self.get_type
self.setType = self.set_type
self.delType = self.get_type
self.getPriority = self.get_priority
self.setPriority = self.set_priority
return StanzaBase.setup(self, xml)
def exception(self, e):
"""
Override exception passback for presence.
......@@ -188,3 +168,13 @@ class Presence(RootStanza):
elif self['type'] == 'subscribe':
self['type'] = 'subscribed'
return StanzaBase.reply(self, clear)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Presence.setShow = Presence.set_show
Presence.getType = Presence.get_type
Presence.setType = Presence.set_type
Presence.delType = Presence.get_type
Presence.getPriority = Presence.get_priority
Presence.setPriority = Presence.set_priority
......@@ -38,23 +38,6 @@ class Roster(ElementBase):
plugin_attrib = 'roster'
interfaces = set(('items',))
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides StanzaBase.setup.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setItems = self.set_items
self.getItems = self.get_items
self.delItems = self.del_items
return ElementBase.setup(self, xml)
def set_items(self, items):
"""
Set the roster entries in the <roster> stanza.
......@@ -123,3 +106,9 @@ class Roster(ElementBase):
register_stanza_plugin(Iq, Roster)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
Roster.setItems = Roster.set_items
Roster.getItems = Roster.get_items
Roster.delItems = Roster.del_items
......@@ -42,8 +42,6 @@ class BaseHandler(object):
this handler.
stream -- The XMLStream instance the handler should monitor.
"""
self.checkDelete = self.check_delete
self.name = name
self.stream = stream
self._destroy = False
......@@ -87,3 +85,8 @@ class BaseHandler(object):
handlers.
"""
return self._destroy
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
BaseHandler.checkDelete = BaseHandler.check_delete
......@@ -117,7 +117,8 @@ class MatchXMLMask(MatcherBase):
return False
# If the mask includes text, compare it.
if mask.text and source.text and source.text.strip() != mask.text.strip():
if mask.text and source.text and \
source.text.strip() != mask.text.strip():
return False
# Compare attributes. The stanza must include the attributes
......
......@@ -140,7 +140,8 @@ class Scheduler(object):
"""Process scheduled tasks."""
self.run = True
try:
while self.run and (self.parentstop is None or not self.parentstop.isSet()):
while self.run and (self.parentstop is None or \
not self.parentstop.isSet()):
wait = 1
updated = False
if self.schedule:
......
......@@ -218,18 +218,6 @@ class ElementBase(object):
xml -- Initialize the stanza with optional existing XML.
parent -- Optional stanza object that contains this stanza.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.initPlugin = self.init_plugin
self._getAttr = self._get_attr
self._setAttr = self._set_attr
self._delAttr = self._del_attr
self._getSubText = self._get_sub_text
self._setSubText = self._set_sub_text
self._delSub = self._del_sub
self.getStanzaValues = self._get_stanza_values
self.setStanzaValues = self._set_stanza_values
self.xml = xml
self.plugins = OrderedDict()
self.iterables = []
......@@ -1076,17 +1064,6 @@ class StanzaBase(ElementBase):
sfrom -- Optional string or JID object of the sender's JID.
sid -- Optional ID value for the stanza.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.setType = self.set_type
self.getTo = self.get_to
self.setTo = self.set_to
self.getFrom = self.get_from
self.setFrom = self.set_from
self.getPayload = self.get_payload
self.setPayload = self.set_payload
self.delPayload = self.del_payload
self.stream = stream
if stream is not None:
self.namespace = stream.default_ns
......@@ -1224,3 +1201,25 @@ class StanzaBase(ElementBase):
return tostring(self.xml, xmlns='',
stanza_ns=self.namespace,
stream=self.stream)
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
ElementBase.initPlugin = ElementBase.init_plugin
ElementBase._getAttr = ElementBase._get_attr
ElementBase._setAttr = ElementBase._set_attr
ElementBase._delAttr = ElementBase._del_attr
ElementBase._getSubText = ElementBase._get_sub_text
ElementBase._setSubText = ElementBase._set_sub_text
ElementBase._delSub = ElementBase._del_sub
ElementBase.getStanzaValues = ElementBase._get_stanza_values
ElementBase.setStanzaValues = ElementBase._set_stanza_values
StanzaBase.setType = StanzaBase.set_type
StanzaBase.getTo = StanzaBase.get_to
StanzaBase.setTo = StanzaBase.set_to
StanzaBase.getFrom = StanzaBase.get_from
StanzaBase.setFrom = StanzaBase.set_from
StanzaBase.getPayload = StanzaBase.get_payload
StanzaBase.setPayload = StanzaBase.set_payload
StanzaBase.delPayload = StanzaBase.del_payload
......@@ -149,19 +149,6 @@ class XMLStream(object):
port -- The port to use for the connection.
Defaults to 0.
"""
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
self.startTLS = self.start_tls
self.registerStanza = self.register_stanza
self.removeStanza = self.remove_stanza
self.registerHandler = self.register_handler
self.removeHandler = self.remove_handler
self.setSocket = self.set_socket
self.sendRaw = self.send_raw
self.getId = self.get_id
self.getNewId = self.new_id
self.sendXML = self.send_xml
self.ssl_support = SSL_SUPPORT
self.ssl_version = ssl.PROTOCOL_TLSv1
self.ca_certs = None
......@@ -970,9 +957,11 @@ class XMLStream(object):
is not caught.
"""
init_old = threading.Thread.__init__
def init(self, *args, **kwargs):
init_old(self, *args, **kwargs)
run_old = self.run
def run_with_except_hook(*args, **kw):
try:
run_old(*args, **kw)
......@@ -982,3 +971,17 @@ class XMLStream(object):
sys.excepthook(*sys.exc_info())
self.run = run_with_except_hook
threading.Thread.__init__ = init
# To comply with PEP8, method names now use underscores.
# Deprecated method names are re-mapped for backwards compatibility.
XMLStream.startTLS = XMLStream.start_tls
XMLStream.registerStanza = XMLStream.register_stanza
XMLStream.removeStanza = XMLStream.remove_stanza
XMLStream.registerHandler = XMLStream.register_handler
XMLStream.removeHandler = XMLStream.remove_handler
XMLStream.setSocket = XMLStream.set_socket
XMLStream.sendRaw = XMLStream.send_raw
XMLStream.getId = XMLStream.get_id
XMLStream.getNewId = XMLStream.new_id
XMLStream.sendXML = XMLStream.send_xml
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment