15 from ..controller.viewinterface import Interface |
15 from ..controller.viewinterface import Interface |
16 |
16 |
17 from ..error import InterfaceException, ValidateException |
17 from ..error import InterfaceException, ValidateException |
18 |
18 |
19 class TwistedInterface(Interface): |
19 class TwistedInterface(Interface): |
|
20 """Class that addes needed function for XML-RPC/SOAP""" |
20 def __init__(self): |
21 def __init__(self): |
21 Interface.__init__(self) |
22 Interface.__init__(self) |
22 |
23 |
23 def listMethods(self): |
24 def listMethods(self): |
24 """Since we override lookupProcedure, its suggested to override |
25 """Since we override lookupProcedure, its suggested to override |
26 """ |
27 """ |
27 return self.listProcedures() |
28 return self.listProcedures() |
28 |
29 |
29 |
30 |
30 def listProcedures(self): |
31 def listProcedures(self): |
31 """Since we override lookupProcedure, its suggested to override |
32 """returns a list of all functions that are allowed to call via XML-RPC.""" |
32 listProcedures too. |
|
33 """ |
|
34 return ['listMethods','status','sms','fax','mail','routes','defaultRoute','bill','telnumber','email'] |
33 return ['listMethods','status','sms','fax','mail','routes','defaultRoute','bill','telnumber','email'] |
35 |
34 |
36 |
35 |
37 class XMLRPCInterface(TwistedInterface,xmlrpc.XMLRPC): |
36 class XMLRPCInterface(TwistedInterface,xmlrpc.XMLRPC): |
|
37 """XML-RPC interface""" |
38 def __init__(self): |
38 def __init__(self): |
39 xmlrpc.XMLRPC.__init__(self) |
39 xmlrpc.XMLRPC.__init__(self) |
40 TwistedInterface.__init__(self) |
40 TwistedInterface.__init__(self) |
41 |
41 |
42 def lookupProcedure(self, procedurePath): |
42 def lookupProcedure(self, procedurePath): |
56 return xmlrpc.Fault(failure.value.code, failure.value.msg) |
56 return xmlrpc.Fault(failure.value.code, failure.value.msg) |
57 return xmlrpc.XMLRPC._ebRender(self, failure) |
57 return xmlrpc.XMLRPC._ebRender(self, failure) |
58 |
58 |
59 |
59 |
60 class SOAPInterface(TwistedInterface,soap.SOAPPublisher): |
60 class SOAPInterface(TwistedInterface,soap.SOAPPublisher): |
|
61 """SOAP interface""" |
61 def __init__(self): |
62 def __init__(self): |
62 soap.SOAPPublisher.__init__(self) |
63 soap.SOAPPublisher.__init__(self) |
63 TwistedInterface.__init__(self) |
64 TwistedInterface.__init__(self) |
64 |
65 |
65 def lookupFunction(self, functionName): |
66 def lookupFunction(self, functionName): |
66 """Lookup published SOAP function. |
|
67 |
|
68 Override in subclasses. Default behaviour - publish methods |
|
69 starting with soap_, if they have true attribute useKeywords |
|
70 they are expected to accept keywords. |
|
71 |
|
72 @return: tuple (callable, useKeywords), or (None, None) if not found. |
|
73 """ |
|
74 if functionName in self.listProcedures(): |
67 if functionName in self.listProcedures(): |
75 function = getattr(self, functionName, None) |
68 function = getattr(self, functionName, None) |
76 if function: |
69 if function: |
77 return function, getattr(function, "useKeywords", False) |
70 return function, getattr(function, "useKeywords", False) |
78 return None |
71 return None |
79 else: |
72 else: |
80 return None |
73 return None |
81 |
74 |
82 def appendResource(root): |
75 def appendResource(root): |
|
76 """adding XML-RPC and SOAP to root.""" |
83 root.putChild('RPC2', XMLRPCInterface()) |
77 root.putChild('RPC2', XMLRPCInterface()) |
84 root.putChild('SOAP', SOAPInterface()) |
78 root.putChild('SOAP', SOAPInterface()) |
85 return root |
79 return root |
86 |
80 |
87 if __name__ == '__main__': |
81 if __name__ == '__main__': |