comparison roundup/cgi/client.py @ 4079:edf526c91412

* Refactor XMLRPC interface. * Make it accessible through web-server.
author Stefan Seefeld <stefan@seefeld.name>
date Wed, 25 Feb 2009 18:17:39 +0000
parents 7d19ed05baa6
children bbab97f8ffb2
comparison
equal deleted inserted replaced
4078:25a6f93a17e1 4079:edf526c91412
14 from roundup.exceptions import * 14 from roundup.exceptions import *
15 from roundup.cgi.exceptions import * 15 from roundup.cgi.exceptions import *
16 from roundup.cgi.form_parser import FormParser 16 from roundup.cgi.form_parser import FormParser
17 from roundup.mailer import Mailer, MessageSendError 17 from roundup.mailer import Mailer, MessageSendError
18 from roundup.cgi import accept_language 18 from roundup.cgi import accept_language
19 from roundup import xmlrpc
19 20
20 def initialiseSecurity(security): 21 def initialiseSecurity(security):
21 '''Create some Permissions and Roles on the security object 22 '''Create some Permissions and Roles on the security object
22 23
23 This function is directly invoked by security.Security.__init__() 24 This function is directly invoked by security.Security.__init__()
352 353
353 def main(self): 354 def main(self):
354 """ Wrap the real main in a try/finally so we always close off the db. 355 """ Wrap the real main in a try/finally so we always close off the db.
355 """ 356 """
356 try: 357 try:
357 self.inner_main() 358 if self.env.get('CONTENT_TYPE') == 'text/xml':
359 self.handle_xmlrpc()
360 else:
361 self.inner_main()
358 finally: 362 finally:
359 if hasattr(self, 'db'): 363 if hasattr(self, 'db'):
360 self.db.close() 364 self.db.close()
365
366
367 def handle_xmlrpc(self):
368
369 # Pull the raw XML out of the form. The "value" attribute
370 # will be the raw content of the POST request.
371 assert self.form.file
372 input = self.form.value
373 # So that the rest of Roundup can query the form in the
374 # usual way, we create an empty list of fields.
375 self.form.list = []
376
377 # Set the charset and language, since other parts of
378 # Roundup may depend upon that.
379 self.determine_charset()
380 self.determine_language()
381 # Open the database as the correct user.
382 self.determine_user()
383
384 # Call the appropriate XML-RPC method.
385 handler = xmlrpc.RoundupDispatcher(self.db, self.userid, self.translator,
386 allow_none=True)
387 output = handler.dispatch(input)
388 self.db.commit()
389
390 self.setHeader("Content-Type", "text/xml")
391 self.setHeader("Content-Length", str(len(output)))
392 self.write(output)
361 393
362 def inner_main(self): 394 def inner_main(self):
363 """Process a request. 395 """Process a request.
364 396
365 The most common requests are handled like so: 397 The most common requests are handled like so:

Roundup Issue Tracker: http://roundup-tracker.org/