iro/newuser.py
branchdevel
changeset 79 17a00b99b9fd
parent 76 9f7da8dc8df8
equal deleted inserted replaced
78:7a4c7b65f20b 79:17a00b99b9fd
     8 #without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     8 #without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     9 #See the GNU General Public License for more details.
     9 #See the GNU General Public License for more details.
    10 
    10 
    11 #You should have received a copy of the GNU General Public License
    11 #You should have received a copy of the GNU General Public License
    12 #along with this program; if not, see <http://www.gnu.org/licenses/>.
    12 #along with this program; if not, see <http://www.gnu.org/licenses/>.
    13 
    13 from twisted.web import soap, xmlrpc, resource, server
    14 class User: 
    14 import logging
       
    15 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s(%(processName)s)-%(levelname)s: %(message)s')
       
    16 
       
    17 class User(object):
    15     '''class for a xmlrpc user
    18     '''class for a xmlrpc user
    16     '''
    19     '''
    17     
    20     
    18     def status(self, apikey, id=None, detailed=False):
    21     def status(self, apikey, id=None, detailed=False):
    19         '''Gibt den aktuellen Status eines Auftrages zurück.
    22         '''Gibt den aktuellen Status eines Auftrages zurück.
    28         job.name[string]: Angebener Name
    31         job.name[string]: Angebener Name
    29         job.status[string]: Status des Auftrages
    32         job.status[string]: Status des Auftrages
    30 
    33 
    31 
    34 
    32         '''
    35         '''
    33         pass
    36         return ""
    34 
    37 
    35     def stop(self, apikey,id):
    38     def stop(self, apikey,id):
    36         '''Stoppt den angegeben Auftrag.
    39         '''Stoppt den angegeben Auftrag.
    37 
    40 
    38         Keywords:
    41         Keywords:
    40         id[hash]: Eine Auftragsnummer
    43         id[hash]: Eine Auftragsnummer
    41 
    44 
    42         Return:
    45         Return:
    43 
    46 
    44         '''
    47         '''
    45         pass
    48         return ""
    46     
    49     
    47     def sms(self, apikey, message, recipients, route="default"):
    50     def sms(self, apikey, message, recipients, route="default"):
    48         '''Versendet eine SMS.
    51         '''Versendet eine SMS.
    49 
    52 
    50         Keywords:
    53         Keywords:
    56 
    59 
    57         Return:
    60         Return:
    58         id[hash]: Die ID des Auftrages
    61         id[hash]: Die ID des Auftrages
    59 
    62 
    60         '''
    63         '''
    61         pass
    64         return ""
    62    
    65    
    63     
    66     
    64     def fax(self, apikey, subject, fax, recipients, route="default"):
    67     def fax(self, apikey, subject, fax, recipients, route="default"):
    65         '''Versendet ein FAX.
    68         '''Versendet ein FAX.
    66 
    69 
    74 
    77 
    75         Return:
    78         Return:
    76         id[hash]: Die ID des Auftrages
    79         id[hash]: Die ID des Auftrages
    77 
    80 
    78         '''
    81         '''
    79         pass
    82         return ""
    80 
    83 
    81     def mail(self, apikey, subject,  body, recipients, frm, route="default"):
    84     def mail(self, apikey, subject,  body, recipients, frm, route="default"):
    82         '''Versendet eine Email.
    85         '''Versendet eine Email.
    83 
    86 
    84         Keywords:
    87         Keywords:
    92 
    95 
    93         Return:
    96         Return:
    94         id[hash]: Die ID des Auftrages
    97         id[hash]: Die ID des Auftrages
    95 
    98 
    96         '''
    99         '''
    97         pass
   100         return ""
    98        
   101        
    99     def routes(self, apikey, typ):
   102     def routes(self, apikey, typ):
   100         '''Gibt eine Liste aller verfügbaren Provider zurück.
   103         '''Gibt eine Liste aller verfügbaren Provider zurück.
   101 
   104 
   102         Keywords:
   105         Keywords:
   106 
   109 
   107         Return:
   110         Return:
   108         providerlist[list]: Eine Liste aller möglichen Provider
   111         providerlist[list]: Eine Liste aller möglichen Provider
   109 
   112 
   110         '''
   113         '''
   111         pass
   114         return ""
   112         
   115         
   113     def defaultRoute(self, apikey, typ):
   116     def defaultRoute(self, apikey, typ):
   114         '''Gibt den Standardprovider zurück.
   117         '''Gibt den Standardprovider zurück.
   115  
   118  
   116         Keywords:
   119         Keywords:
   121         Return:
   124         Return:
   122         provider[string]: Der Standardprovider für den angeben Typ
   125         provider[string]: Der Standardprovider für den angeben Typ
   123 
   126 
   124 
   127 
   125         '''
   128         '''
   126         pass
   129         return ""
   127 
   130 
   128     def statistic(self,apikey):
   131     def statistic(self,apikey):
   129         '''Gibt eine Statik zurück über die versendendeten Nachrichten und des Preises.
   132         '''Gibt eine Statik zurück über die versendendeten Nachrichten und des Preises.
   130 
   133 
   131         Keywords:
   134         Keywords:
   132         apikey[string]: Der API Key
   135         apikey[string]: Der API Key
   133 
   136 
   134         Return:
   137         Return:
   135         statistic[list]: Eine Liste nach Nachrichtentypen
   138         statistic[list]: Eine Liste nach Nachrichtentypen
   136         '''
   139         '''
   137         pass
   140         return ""
       
   141 
       
   142     def listMethods(self):
       
   143         """Since we override lookupProcedure, its suggested to override
       
   144         listProcedures too.
       
   145         """
       
   146         return self.listProcedures()
       
   147   
       
   148 
       
   149     def listProcedures(self):
       
   150         """Since we override lookupProcedure, its suggested to override
       
   151         listProcedures too.
       
   152         """
       
   153         return ['listMethods','status','stop','sms','fax','mail','routes','defaultRoute','statistic']
       
   154 
       
   155 
       
   156 class XMLRPCUser(User,xmlrpc.XMLRPC): 
       
   157     def __init__(self):
       
   158         xmlrpc.XMLRPC.__init__(self) 
       
   159         User.__init__(self)
       
   160         self.allowNone = True
       
   161     
       
   162     def lookupProcedure(self, procedurePath):
       
   163         logging.debug("lookupProcedure('%s')"%procedurePath)
       
   164         if procedurePath not in self.listProcedures():
       
   165             raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
       
   166                         "procedure %s not found" % procedurePath)
       
   167         try:
       
   168             return getattr(self,procedurePath)
       
   169         except KeyError:
       
   170             raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
       
   171                         "procedure %s not found" % procedurePath)
       
   172 
       
   173 class SOAPUser(User,soap.SOAPPublisher): 
       
   174     def __init__(self):
       
   175         soap.SOAPPublisher.__init__(self) 
       
   176         User.__init__(self)
       
   177         
       
   178     def lookupFunction(self, functionName):
       
   179         """Lookup published SOAP function.
       
   180 
       
   181         Override in subclasses. Default behaviour - publish methods
       
   182         starting with soap_, if they have true attribute useKeywords
       
   183         they are expected to accept keywords.
       
   184         
       
   185         @return: tuple (callable, useKeywords), or (None, None) if not found.
       
   186         """
       
   187         if functionName in self.listProcedures():
       
   188             function = getattr(self, functionName, None)
       
   189             if function:
       
   190                 return function, getattr(function, "useKeywords", False)
       
   191             return None
       
   192         else:
       
   193             return None
       
   194 
       
   195 
       
   196 def main():
       
   197     from twisted.internet import reactor
       
   198     root = resource.Resource()
       
   199     root.putChild('RPC2', XMLRPCUser())
       
   200     root.putChild('SOAP', SOAPUser())
       
   201     reactor.listenTCP(7080, server.Site(root))
       
   202     reactor.run()
       
   203 
       
   204 if __name__ == '__main__':
       
   205     main()