--- a/iro/newuser.py Sun Dec 18 13:42:10 2011 +0100
+++ b/iro/newuser.py Sun Dec 18 13:42:53 2011 +0100
@@ -10,8 +10,11 @@
#You should have received a copy of the GNU General Public License
#along with this program; if not, see <http://www.gnu.org/licenses/>.
+from twisted.web import soap, xmlrpc, resource, server
+import logging
+logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s(%(processName)s)-%(levelname)s: %(message)s')
-class User:
+class User(object):
'''class for a xmlrpc user
'''
@@ -30,7 +33,7 @@
'''
- pass
+ return ""
def stop(self, apikey,id):
'''Stoppt den angegeben Auftrag.
@@ -42,7 +45,7 @@
Return:
'''
- pass
+ return ""
def sms(self, apikey, message, recipients, route="default"):
'''Versendet eine SMS.
@@ -58,7 +61,7 @@
id[hash]: Die ID des Auftrages
'''
- pass
+ return ""
def fax(self, apikey, subject, fax, recipients, route="default"):
@@ -76,7 +79,7 @@
id[hash]: Die ID des Auftrages
'''
- pass
+ return ""
def mail(self, apikey, subject, body, recipients, frm, route="default"):
'''Versendet eine Email.
@@ -94,7 +97,7 @@
id[hash]: Die ID des Auftrages
'''
- pass
+ return ""
def routes(self, apikey, typ):
'''Gibt eine Liste aller verfügbaren Provider zurück.
@@ -108,7 +111,7 @@
providerlist[list]: Eine Liste aller möglichen Provider
'''
- pass
+ return ""
def defaultRoute(self, apikey, typ):
'''Gibt den Standardprovider zurück.
@@ -123,7 +126,7 @@
'''
- pass
+ return ""
def statistic(self,apikey):
'''Gibt eine Statik zurück über die versendendeten Nachrichten und des Preises.
@@ -134,4 +137,69 @@
Return:
statistic[list]: Eine Liste nach Nachrichtentypen
'''
- pass
+ return ""
+
+ def listMethods(self):
+ """Since we override lookupProcedure, its suggested to override
+ listProcedures too.
+ """
+ return self.listProcedures()
+
+
+ def listProcedures(self):
+ """Since we override lookupProcedure, its suggested to override
+ listProcedures too.
+ """
+ return ['listMethods','status','stop','sms','fax','mail','routes','defaultRoute','statistic']
+
+
+class XMLRPCUser(User,xmlrpc.XMLRPC):
+ def __init__(self):
+ xmlrpc.XMLRPC.__init__(self)
+ User.__init__(self)
+ self.allowNone = True
+
+ def lookupProcedure(self, procedurePath):
+ logging.debug("lookupProcedure('%s')"%procedurePath)
+ if procedurePath not in self.listProcedures():
+ raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
+ "procedure %s not found" % procedurePath)
+ try:
+ return getattr(self,procedurePath)
+ except KeyError:
+ raise xmlrpc.NoSuchFunction(self.NOT_FOUND,
+ "procedure %s not found" % procedurePath)
+
+class SOAPUser(User,soap.SOAPPublisher):
+ def __init__(self):
+ soap.SOAPPublisher.__init__(self)
+ User.__init__(self)
+
+ def lookupFunction(self, functionName):
+ """Lookup published SOAP function.
+
+ Override in subclasses. Default behaviour - publish methods
+ starting with soap_, if they have true attribute useKeywords
+ they are expected to accept keywords.
+
+ @return: tuple (callable, useKeywords), or (None, None) if not found.
+ """
+ if functionName in self.listProcedures():
+ function = getattr(self, functionName, None)
+ if function:
+ return function, getattr(function, "useKeywords", False)
+ return None
+ else:
+ return None
+
+
+def main():
+ from twisted.internet import reactor
+ root = resource.Resource()
+ root.putChild('RPC2', XMLRPCUser())
+ root.putChild('SOAP', SOAPUser())
+ reactor.listenTCP(7080, server.Site(root))
+ reactor.run()
+
+if __name__ == '__main__':
+ main()