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. |
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() |