1 from functools import partial |
1 from functools import partial |
|
2 from collections import OrderedDict |
2 |
3 |
3 from ..error import NoRoute, NoTyp, ValidateException, NoProvider |
4 from ..error import NoRoute, NoTyp, ValidateException, NoProvider |
4 from ..config import Option, Config |
5 from ..config import Option, Config |
5 |
6 |
6 class Provider(Config): |
7 class Provider(Config): |
7 """Base class for Providerbackends.""" |
8 """Base class for Providerbackends.""" |
8 |
9 |
9 testmode = False |
10 testmode = False |
10 """- **True** -- no message to external provider should be send. |
11 """- **True** -- no message to external provider should be send. |
11 - **False** (default) -- message are send to external provider.""" |
12 - **False** (default) -- message are send to external provider.""" |
12 def __init__(self, name, typs={}): |
13 def __init__(self, name, typs={}, options=[]): |
13 """Constructor for Provider class. |
14 """Constructor for Provider class. |
14 |
15 |
15 :param string name: Name of the Provider. |
16 :param string name: Name of the Provider. |
16 :param dict typs: A Dictonary with typs and routes. |
17 :param dict typs: A Dictonary with typs and routes. |
|
18 :param items options: [("name",Option(...)),...] |
17 |
19 |
18 >>> p = Provider("myProvider",{"sms":["route1","route2"]}) |
20 >>> p = Provider("myProvider",{"sms":["route1","route2"]}) |
19 """ |
21 """ |
20 |
22 |
21 Config.__init__(self, name) |
23 Config.__init__(self, name, OrderedDict([ |
|
24 ("typ",Option(vProvider, long="One available provider typ.", must=True, default=name)) |
|
25 ]+options) |
|
26 ) |
22 self.typs=typs |
27 self.typs=typs |
23 self.testmode = False |
28 self.testmode = False |
24 |
|
25 self.options = { |
|
26 "typ":Option(vProvider, long="One available provider typ.", must=True, default=name) |
|
27 } |
|
28 """Options dict for Options used in configuration file (see :class:`iro.config.Option`). Ordering of configuration fields are done by :attr:`order`. |
|
29 |
|
30 Sample:: |
|
31 |
|
32 {"typ":Option(vProvider, long="One available provider typ.", must=True, default="default")} |
|
33 |
|
34 A child class typically use update to add more options (see code of :class:`iro.offer.smtp.SMTP`). |
|
35 """ |
|
36 |
|
37 self.order = ["typ"] |
|
38 """ A list for ordering the options dict (:attr:`options`). """ |
|
39 |
29 |
40 def send(self, typ, route, recipient, message): |
30 def send(self, typ, route, recipient, message): |
41 """Main send function, that is called, for every single message. |
31 """Main send function, that is called, for every single message. |
42 |
32 |
43 .. note:: |
33 .. note:: |