From 151f1e3fd37dbe0b5782094e1513504dcabd31c5 Mon Sep 17 00:00:00 2001 From: "markh%activestate.com" Date: Tue, 3 Apr 2001 10:41:09 +0000 Subject: [PATCH] Allow services to use interface names as a string, just like regular components. Not part of the build. git-svn-id: svn://10.0.0.236/trunk@91120 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/extensions/python/xpcom/components.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mozilla/extensions/python/xpcom/components.py b/mozilla/extensions/python/xpcom/components.py index 1144305316a..4e7318bf63f 100644 --- a/mozilla/extensions/python/xpcom/components.py +++ b/mozilla/extensions/python/xpcom/components.py @@ -24,6 +24,13 @@ import types StringTypes = [types.StringType, types.UnicodeType] +def _get_good_iid(iid): + if iid is None: + iid = _xpcom.IID_nsISupports + elif type(iid) in StringTypes and len(iid)>0 and iid[0] != "{": + iid = getattr(interfaces, iid) + return iid + # The "manager" object. manager = xpcom.client.Interface(_xpcom.NS_GetGlobalComponentManager(), _xpcom.IID_nsIComponentManager) @@ -144,13 +151,9 @@ class _Class: raise AttributeError, "%s class has no attribute '%s'" % (self.contractid, attr) def createInstance(self, iid = None): import xpcom.client - if iid is None: - iid = _xpcom.IID_nsISupports - elif type(iid) in StringTypes and len(iid)>0 and iid[0] != "{": - iid = getattr(interfaces, iid) - return xpcom.client.Component(self.contractid, iid) + return xpcom.client.Component(self.contractid, _get_good_iid(iid)) def getService(self, iid): - return _xpcom.GetGlobalServiceManager().getService(self.contractid, iid) + return _xpcom.GetGlobalServiceManager().getService(self.contractid, _get_good_iid(iid)) class _Classes(_ComponentCollection): def __init__(self):