1 from functools import partial |
1 from functools import partial |
2 |
2 |
3 from iro.error import NoRoute, NoTyp |
3 from ..error import NoRoute, NoTyp, ValidateException, NoProvider, NeededOption |
|
4 from ..config import Option |
|
5 |
4 class Provider(): |
6 class Provider(): |
5 def __init__(self, name, config, typs={}): |
7 def __init__(self, name, config, typs={}): |
6 self.name = name |
8 self.name = name |
7 self.config = config |
9 self.config = config |
8 self.typs=typs |
10 self.typs=typs |
9 self.testmode = False |
11 self.testmode = False |
10 |
12 |
11 self.loadConfig() |
13 self.options = { |
|
14 "typ":Option(vProvider, long="One available provider typ.", must=True) |
|
15 } |
12 |
16 |
13 def loadConfig(self): |
17 def loadConfig(self): |
|
18 c=dict(self.config) |
|
19 for o in self.options: |
|
20 try: |
|
21 value = self.options[o].validate(c[o],o) |
|
22 setattr(self, o, value) |
|
23 except (KeyError): |
|
24 if self.options[o].must: |
|
25 raise NeededOption(self.name, o) |
|
26 elif self.options[o].default is not None: |
|
27 setattr(self,o,self.options[o].default) |
|
28 |
14 for (n, v) in self.config: |
29 for (n, v) in self.config: |
15 if n == "typ": |
30 if n == "typ": |
16 self.typ = v |
31 self.typ = v |
17 |
32 |
18 def send(self, typ, route, recipient, message): |
33 def send(self, typ, route, recipient, message): |