iro/offer/provider.py
branchdevel
changeset 186 b381eaa774ab
parent 183 07ee5543751b
child 220 602720314930
--- a/iro/offer/provider.py	Thu Feb 23 16:59:49 2012 +0100
+++ b/iro/offer/provider.py	Sat Feb 25 16:12:07 2012 +0100
@@ -1,35 +1,18 @@
 from functools import partial
 
-from ..error import NoRoute, NoTyp, ValidateException, NoProvider, NeededOption
-from ..config import Option
+from ..error import NoRoute, NoTyp, ValidateException, NoProvider
+from ..config import Option, Config
 
-class Provider():
-    def __init__(self, name, config, typs={}):
-        self.name = name
-        self.config = config
+class Provider(Config):
+    def __init__(self, name, typs={}):
+        Config.__init__(self, name)
         self.typs=typs
         self.testmode = False
-        
+
         self.options = {
                 "typ":Option(vProvider, long="One available provider typ.", must=True)
                 }
 
-    def loadConfig(self):
-        c=dict(self.config)
-        for o in self.options:
-            try:
-                value = self.options[o].validate(c[o],o)
-                setattr(self, o, value)
-            except (KeyError):
-                if self.options[o].must:
-                    raise NeededOption(self.name, o) 
-                elif self.options[o].default is not None:
-                    setattr(self,o,self.options[o].default)
-
-        for (n, v) in self.config:
-            if n == "typ":
-                self.typ = v
-
     def send(self, typ, route, recipient, message):
         pass
 
@@ -43,7 +26,9 @@
 
 def getProvider(name, typ, config):
     try:
-        return providers[typ](name,config)
+        p = providers[typ](name)
+        p.load(config)
+        return p
     except KeyError:
         raise NoProvider(typ)