offer.provider now handles the options dict and loadConfig is only in Provider class
from functools import partial
from ..error import NoRoute, NoTyp, ValidateException, NoProvider, NeededOption
from ..config import Option
class Provider():
def __init__(self, name, config, typs={}):
self.name = name
self.config = config
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
def getSendFunc(self, typ, route):
try:
if route not in self.typs[typ]:
raise NoRoute(route)
except KeyError:
raise NoTyp(route)
return partial(self.send, typ, route)
def getProvider(name, typ, config):
try:
return providers[typ](name,config)
except KeyError:
raise NoProvider(typ)
def vProvider(typ, field):
if typ not in providers.keys():
raise ValidateException()
return typ
providers={}