iro/offer/provider.py
branchdevel
changeset 253 e8d56537c9cc
parent 220 602720314930
child 254 de301b8c58d9
--- a/iro/offer/provider.py	Sun Mar 25 20:11:34 2012 +0200
+++ b/iro/offer/provider.py	Sun Mar 25 20:14:35 2012 +0200
@@ -4,7 +4,20 @@
 from ..config import Option, Config
 
 class Provider(Config):
+    """Base class for Providerbackends."""
+
+    testmode = False
+    """- **True** -- no message to external provider should be send.
+    - **False** (default) -- message are send to external provider."""
     def __init__(self, name, typs={}):
+        """Constructor for Provider class.
+        
+        :param string name: Name of the Provider.
+        :param dict typs: A Dictonary with typs and routes.
+
+        >>> p = Provider("myProvider",{"sms":["route1","route2"]})
+        """
+
         Config.__init__(self, name)
         self.typs=typs
         self.testmode = False
@@ -12,13 +25,33 @@
         self.options = {
                 "typ":Option(vProvider, long="One available provider typ.", must=True, default=name)
                 }
+        """Options dict for Options used in configuration file (see :class:`iro.config.Option`). Ordering of configuration fields are done by :attr:`order`. 
+        
+        Sample::
+        
+               {"typ":Option(vProvider, long="One available provider typ.", must=True, default="default")}
+        
+        A child class typically use update to add more options (see code of :class:`iro.offer.smtp.SMTP`).
+        """
 
         self.order = ["typ"]
+        """ A list for ordering the options dict (:attr:`options`). """
 
     def send(self, typ, route, recipient, message):
+        """Main send function, that is called, for every single message.
+
+        .. note::
+            This function is not used directly. Normally :func:`~iro.offer.provider.Provider.getSendFunc` return this function with typ and route bound."""
         pass
 
     def getSendFunc(self, typ, route):
+        """Returns the actually send Functionfor a given typ and route.
+        
+        Normally it returns the send function with typ and route bound.
+
+        :raises: :exc:`~iro.error.NoRoute`, :exc:`~iro.error.NoTyp`
+        """
+
         try:
             if route not in self.typs[typ]:
                 raise NoRoute(route)
@@ -27,6 +60,12 @@
         return partial(self.send, typ, route)
 
 def getProvider(name, typ, config):
+    '''creates a provider object and init this with config.
+   
+    :param dict config: The Configuration dict. Normally you use ``configParser.items("section")``.
+    :param string typ: A valid typ
+    :raises: :exc:`~iro.error.NoProvider`
+    '''
     try:
         p = providers[typ](name)
         p.load(config)
@@ -35,8 +74,26 @@
         raise NoProvider(typ)
 
 def vProvider(typ, field):
+    '''validator to test the existence of the typ.
+
+    :param string typ: A typ
+    :param string field: A field name used for the Exception.
+    :return:
+        - valid -- returns typ
+        - invalid -- raises :class:`~iro.error.ValidateException`
+
+    :raises: :exc:`~iro.error.ValidateException`
+    '''
     if typ not in providers.keys():
         raise ValidateException()
     return typ
 
 providers={}
+"""Avalable Providers.
+    - **key** -- typ of provider (see configuration typ field).
+    - **value** -- class to handle specific Providertyp.
+
+To extend provider typs, just add this new typ to this dict.
+see :doc:`provider`
+   
+"""