From e1aa4d0b93f09b92506af8bb21e87c367905e194 Mon Sep 17 00:00:00 2001 From: Brian Beggs Date: Wed, 2 Jun 2010 19:34:43 +0800 Subject: Added .pydevproject to the .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 15997ce4..8b41dac4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .project build/ *.swp +.pydevproject -- cgit v1.2.3 From 184f7cb8a4d2835c317eca7db129fb06d92a336a Mon Sep 17 00:00:00 2001 From: Brian Beggs Date: Wed, 2 Jun 2010 20:28:49 +0800 Subject: moddified plugin loading so plugins located outside of the plugins directory in sleek may be loaded. Added optional argument pluginModule that is a string that represents the module the desired plugin should be loaded from. An exception on plugin loading now also will not cause the program to exit. The exception is caught and loading of other plugins contains. --- .gitignore | 1 + sleekxmpp/basexmpp.py | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 8b41dac4..6257bbf6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build/ *.swp .pydevproject +.settings diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index a916fe86..5f330176 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -1,9 +1,9 @@ """ - SleekXMPP: The Sleek XMPP Library - Copyright (C) 2010 Nathanael C. Fritz - This file is part of SleekXMPP. + SleekXMPP: The Sleek XMPP Library + Copyright (C) 2010 Nathanael C. Fritz + This file is part of SleekXMPP. - See the file license.txt for copying permission. + See the file license.txt for copying permission. """ from __future__ import with_statement, unicode_literals @@ -91,15 +91,18 @@ class basexmpp(object): if not self.plugin[idx].post_inited: self.plugin[idx].post_init() return super(basexmpp, self).process(*args, **kwargs) - def registerPlugin(self, plugin, pconfig = {}): + def registerPlugin(self, plugin, pconfig = {}, pluginModule = None): """Register a plugin not in plugins.__init__.__all__ but in the plugins directory.""" # discover relative "path" to the plugins module from the main app, and import it. # TODO: # gross, this probably isn't necessary anymore, especially for an installed module - __import__("%s.%s" % (globals()['plugins'].__name__, plugin)) + if pluginModule: + module = __import__("%s.%s" % (pluginModule, plugin), globals(), locals(), [plugin]) + else: + module = __import__("%s.%s" % (globals()['plugins'].__name__, plugin), globals(), locals(), [plugin]) # init the plugin class - self.plugin[plugin] = getattr(getattr(plugins, plugin), plugin)(self, pconfig) # eek + self.plugin[plugin] = getattr(module, plugin)(self, pconfig) # eek # all of this for a nice debug? sure. xep = '' if hasattr(self.plugin[plugin], 'xep'): -- cgit v1.2.3 From 2a43f59a588af7206b0d1935e85fbb9577b3c200 Mon Sep 17 00:00:00 2001 From: Brian Beggs Date: Wed, 2 Jun 2010 20:45:42 +0800 Subject: added try/catch block to plugin loading --- sleekxmpp/basexmpp.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 5f330176..b78c255c 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -97,18 +97,21 @@ class basexmpp(object): # discover relative "path" to the plugins module from the main app, and import it. # TODO: # gross, this probably isn't necessary anymore, especially for an installed module - if pluginModule: - module = __import__("%s.%s" % (pluginModule, plugin), globals(), locals(), [plugin]) - else: - module = __import__("%s.%s" % (globals()['plugins'].__name__, plugin), globals(), locals(), [plugin]) - # init the plugin class - self.plugin[plugin] = getattr(module, plugin)(self, pconfig) # eek - # all of this for a nice debug? sure. - xep = '' - if hasattr(self.plugin[plugin], 'xep'): - xep = "(XEP-%s) " % self.plugin[plugin].xep - logging.debug("Loaded Plugin %s%s" % (xep, self.plugin[plugin].description)) - + try: + if pluginModule: + module = __import__(pluginModule, globals(), locals(), [plugin]) + else: + module = __import__("%s.%s" % (globals()['plugins'].__name__, plugin), globals(), locals(), [plugin]) + # init the plugin class + self.plugin[plugin] = getattr(module, plugin)(self, pconfig) # eek + # all of this for a nice debug? sure. + xep = '' + if hasattr(self.plugin[plugin], 'xep'): + xep = "(XEP-%s) " % self.plugin[plugin].xep + logging.debug("Loaded Plugin %s%s" % (xep, self.plugin[plugin].description)) + except: + logging.error("Unable to load plugin: %s" %(plugin) ) + def register_plugins(self): """Initiates all plugins in the plugins/__init__.__all__""" if self.plugin_whitelist: -- cgit v1.2.3 From b03e6168a8131330390df35572345bfe07ba73fa Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Wed, 2 Jun 2010 12:40:52 +0800 Subject: if binding and session are advertised in the same go, do session first --- sleekxmpp/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sleekxmpp/__init__.py b/sleekxmpp/__init__.py index 6995f7c9..9297ad3f 100644 --- a/sleekxmpp/__init__.py +++ b/sleekxmpp/__init__.py @@ -69,6 +69,7 @@ class ClientXMPP(basexmpp, XMLStream): #TODO: Use stream state here self.authenticated = False self.sessionstarted = False + self.bound = False self.registerHandler(Callback('Stream Features', MatchXPath('{http://etherx.jabber.org/streams}features'), self._handleStreamFeatures, thread=True)) self.registerHandler(Callback('Roster Update', MatchXPath('{%s}iq/{jabber:iq:roster}query' % self.default_ns), self._handleRoster, thread=True)) #self.registerHandler(Callback('Roster Update', MatchXMLMask("" % self.default_ns), self._handlePresenceSubscribe, thread=True)) @@ -248,6 +249,7 @@ class ClientXMPP(basexmpp, XMLStream): response = iq.send() #response = self.send(iq, self.Iq(sid=iq['id'])) self.set_jid(response.xml.find('{urn:ietf:params:xml:ns:xmpp-bind}bind/{urn:ietf:params:xml:ns:xmpp-bind}jid').text) + self.bound = True logging.info("Node set to: %s" % self.fulljid) if "{urn:ietf:params:xml:ns:xmpp-session}session" not in self.features: logging.debug("Established Session") @@ -255,7 +257,7 @@ class ClientXMPP(basexmpp, XMLStream): self.event("session_start") def handler_start_session(self, xml): - if self.authenticated: + if self.authenticated and self.bound: iq = self.makeIqSet(xml) response = iq.send() logging.debug("Established Session") -- cgit v1.2.3 From 85a2715c7de1f436b5553a73f74c30cffa8bc04f Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Wed, 2 Jun 2010 12:44:54 +0800 Subject: hack fix for session before bind --- sleekxmpp/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sleekxmpp/__init__.py b/sleekxmpp/__init__.py index 9297ad3f..23e8c9b8 100644 --- a/sleekxmpp/__init__.py +++ b/sleekxmpp/__init__.py @@ -70,6 +70,7 @@ class ClientXMPP(basexmpp, XMLStream): self.authenticated = False self.sessionstarted = False self.bound = False + self.bindfail = False self.registerHandler(Callback('Stream Features', MatchXPath('{http://etherx.jabber.org/streams}features'), self._handleStreamFeatures, thread=True)) self.registerHandler(Callback('Roster Update', MatchXPath('{%s}iq/{jabber:iq:roster}query' % self.default_ns), self._handleRoster, thread=True)) #self.registerHandler(Callback('Roster Update', MatchXMLMask("" % self.default_ns), self._handlePresenceSubscribe, thread=True)) @@ -251,7 +252,7 @@ class ClientXMPP(basexmpp, XMLStream): self.set_jid(response.xml.find('{urn:ietf:params:xml:ns:xmpp-bind}bind/{urn:ietf:params:xml:ns:xmpp-bind}jid').text) self.bound = True logging.info("Node set to: %s" % self.fulljid) - if "{urn:ietf:params:xml:ns:xmpp-session}session" not in self.features: + if "{urn:ietf:params:xml:ns:xmpp-session}session" not in self.features or self.bindfail: logging.debug("Established Session") self.sessionstarted = True self.event("session_start") @@ -263,6 +264,9 @@ class ClientXMPP(basexmpp, XMLStream): logging.debug("Established Session") self.sessionstarted = True self.event("session_start") + else: + #bind probably hasn't happened yet + self.bindfail = True def _handleRoster(self, iq, request=False): if iq['type'] == 'set' or (iq['type'] == 'result' and request): -- cgit v1.2.3