Resolve plugin dependency chains with XEP-0115.

The post_init() system can only reliably handle a single layer
of dependencies between plugins, but PEP plugins with XEP-0115
exceed that limit and plugins can be post_init'ed out of order. To
resolve this, we will special case XEP-0115 to be post_init'ed
first until the new plugin system with dependency tracking is
stable.
This commit is contained in:
Lance Stout 2012-03-10 12:48:35 -08:00
parent 7f71ac7e0a
commit 91155444c0
4 changed files with 17 additions and 15 deletions

View file

@ -185,6 +185,16 @@ class BaseXMPP(XMLStream):
- The send queue processor - The send queue processor
- The scheduler - The scheduler
""" """
# The current post_init() process can only resolve a single
# layer of inter-plugin dependencies. However, XEP-0115 and
# plugins which depend on it exceeds this limit and can cause
# failures if plugins are post_inited out of order, so we must
# manually process XEP-0115 first.
if 'xep_0115' in self.plugin:
if not self.plugin['xep_0115'].post_inited:
self.plugin['xep_0115'].post_init()
for name in self.plugin: for name in self.plugin:
if not self.plugin[name].post_inited: if not self.plugin[name].post_inited:
self.plugin[name].post_init() self.plugin[name].post_init()
@ -257,10 +267,6 @@ class BaseXMPP(XMLStream):
else: else:
raise NameError("Plugin %s not in plugins.__all__." % plugin) raise NameError("Plugin %s not in plugins.__all__." % plugin)
# Resolve plugin inter-dependencies.
for plugin in self.plugin:
self.plugin[plugin].post_init()
def __getitem__(self, key): def __getitem__(self, key):
"""Return a plugin given its name, if it has been registered.""" """Return a plugin given its name, if it has been registered."""
if key in self.plugin: if key in self.plugin:

View file

@ -27,7 +27,9 @@ __all__ = [
'xep_0086', # Legacy Error Codes 'xep_0086', # Legacy Error Codes
'xep_0092', # Software Version 'xep_0092', # Software Version
'xep_0115', # Entity Capabilities 'xep_0115', # Entity Capabilities
'xep_0118', # User Tune
'xep_0128', # Extended Service Discovery 'xep_0128', # Extended Service Discovery
'xep_0163', # Personal Eventing Protocol
'xep_0199', # Ping 'xep_0199', # Ping
'xep_0202', # Entity Time 'xep_0202', # Entity Time
'xep_0203', # Delayed Delivery 'xep_0203', # Delayed Delivery

View file

@ -7,6 +7,9 @@ class TestStreamPresence(SleekTest):
Test handling roster updates. Test handling roster updates.
""" """
def setUp(self):
self.stream_start(jid='tester@localhost', plugins=[])
def tearDown(self): def tearDown(self):
self.stream_close() self.stream_close()
@ -25,7 +28,6 @@ class TestStreamPresence(SleekTest):
# The presence_unavailable event should be triggered. # The presence_unavailable event should be triggered.
events.add('unavailable') events.add('unavailable')
self.stream_start()
self.xmpp.add_event_handler('got_offline', got_offline) self.xmpp.add_event_handler('got_offline', got_offline)
self.xmpp.add_event_handler('presence_unavailable', unavailable) self.xmpp.add_event_handler('presence_unavailable', unavailable)
@ -48,7 +50,6 @@ class TestStreamPresence(SleekTest):
def got_offline(presence): def got_offline(presence):
events.append('got_offline') events.append('got_offline')
self.stream_start()
self.xmpp.add_event_handler('got_offline', got_offline) self.xmpp.add_event_handler('got_offline', got_offline)
# Setup roster. Use a 'set' instead of 'result' so we # Setup roster. Use a 'set' instead of 'result' so we
@ -98,7 +99,6 @@ class TestStreamPresence(SleekTest):
def got_online(p): def got_online(p):
events.add('got_online') events.add('got_online')
self.stream_start()
self.xmpp.add_event_handler('presence_available', presence_available) self.xmpp.add_event_handler('presence_available', presence_available)
self.xmpp.add_event_handler('got_online', got_online) self.xmpp.add_event_handler('got_online', got_online)
@ -128,7 +128,6 @@ class TestStreamPresence(SleekTest):
def changed_subscription(p): def changed_subscription(p):
events.add('changed_subscription') events.add('changed_subscription')
self.stream_start(jid='tester@localhost')
self.xmpp.add_event_handler('changed_subscription', self.xmpp.add_event_handler('changed_subscription',
changed_subscription) changed_subscription)
@ -175,8 +174,6 @@ class TestStreamPresence(SleekTest):
def changed_subscription(p): def changed_subscription(p):
events.add('changed_subscription') events.add('changed_subscription')
self.stream_start(jid='tester@localhost')
self.xmpp.add_event_handler('changed_subscription', self.xmpp.add_event_handler('changed_subscription',
changed_subscription) changed_subscription)
self.xmpp.add_event_handler('presence_subscribe', self.xmpp.add_event_handler('presence_subscribe',
@ -205,8 +202,6 @@ class TestStreamPresence(SleekTest):
events = [] events = []
self.stream_start()
ptypes = ['available', 'away', 'dnd', 'xa', 'chat', ptypes = ['available', 'away', 'dnd', 'xa', 'chat',
'unavailable', 'subscribe', 'subscribed', 'unavailable', 'subscribe', 'subscribed',
'unsubscribe', 'unsubscribed'] 'unsubscribe', 'unsubscribed']
@ -254,7 +249,6 @@ class TestStreamPresence(SleekTest):
def test_changed_status(self): def test_changed_status(self):
"""Test that the changed_status event is handled properly.""" """Test that the changed_status event is handled properly."""
events = [] events = []
self.stream_start()
def changed_status(presence): def changed_status(presence):
events.append(presence['type']) events.append(presence['type'])

View file

@ -226,7 +226,7 @@ class TestStreamRoster(SleekTest):
def testRosterUnicode(self): def testRosterUnicode(self):
"""Test that JIDs with Unicode values are handled properly.""" """Test that JIDs with Unicode values are handled properly."""
self.stream_start() self.stream_start(plugins=[])
self.recv(""" self.recv("""
<iq to="tester@localhost" type="set" id="1"> <iq to="tester@localhost" type="set" id="1">
<query xmlns="jabber:iq:roster"> <query xmlns="jabber:iq:roster">
@ -267,7 +267,7 @@ class TestStreamRoster(SleekTest):
def testSendLastPresence(self): def testSendLastPresence(self):
"""Test that sending the last presence works.""" """Test that sending the last presence works."""
self.stream_start() self.stream_start(plugins=[])
self.xmpp.send_presence(pshow='dnd') self.xmpp.send_presence(pshow='dnd')
self.xmpp.auto_authorize = True self.xmpp.auto_authorize = True
self.xmpp.auto_subscribe = True self.xmpp.auto_subscribe = True