Mercurial > p > roundup > code
comparison roundup/cgi/client.py @ 5556:d75aa88c2a99 REST-rebased
Added RestInstance and calling rest from client.py
committer: Ralf Schlatterbeck <rsc@runtux.com>
| author | Chau Nguyen <dangchau1991@yahoo.com> |
|---|---|
| date | Tue, 29 Jan 2019 15:27:37 +0100 |
| parents | 7b663b588292 |
| children | 70df783c4c0b |
comparison
equal
deleted
inserted
replaced
| 5555:7b663b588292 | 5556:d75aa88c2a99 |
|---|---|
| 33 DetectorError, SeriousError) | 33 DetectorError, SeriousError) |
| 34 from roundup.cgi.form_parser import FormParser | 34 from roundup.cgi.form_parser import FormParser |
| 35 from roundup.mailer import Mailer, MessageSendError | 35 from roundup.mailer import Mailer, MessageSendError |
| 36 from roundup.cgi import accept_language | 36 from roundup.cgi import accept_language |
| 37 from roundup import xmlrpc | 37 from roundup import xmlrpc |
| 38 from roundup import rest | |
| 38 | 39 |
| 39 from roundup.anypy.cookie_ import CookieError, BaseCookie, SimpleCookie, \ | 40 from roundup.anypy.cookie_ import CookieError, BaseCookie, SimpleCookie, \ |
| 40 get_cookie_date | 41 get_cookie_date |
| 41 from roundup.anypy import http_ | 42 from roundup.anypy import http_ |
| 42 from roundup.anypy import urllib_ | 43 from roundup.anypy import urllib_ |
| 426 """ Wrap the real main in a try/finally so we always close off the db. | 427 """ Wrap the real main in a try/finally so we always close off the db. |
| 427 """ | 428 """ |
| 428 try: | 429 try: |
| 429 if self.path == 'xmlrpc': | 430 if self.path == 'xmlrpc': |
| 430 self.handle_xmlrpc() | 431 self.handle_xmlrpc() |
| 432 elif self.path == 'rest' or self.path[:5] == 'rest/': | |
| 433 self.handle_rest() | |
| 431 else: | 434 else: |
| 432 self.inner_main() | 435 self.inner_main() |
| 433 finally: | 436 finally: |
| 434 if hasattr(self, 'db'): | 437 if hasattr(self, 'db'): |
| 435 self.db.close() | 438 self.db.close() |
| 479 self.translator, | 482 self.translator, |
| 480 allow_none=True) | 483 allow_none=True) |
| 481 output = handler.dispatch(input) | 484 output = handler.dispatch(input) |
| 482 | 485 |
| 483 self.setHeader("Content-Type", "text/xml") | 486 self.setHeader("Content-Type", "text/xml") |
| 487 self.setHeader("Content-Length", str(len(output))) | |
| 488 self.write(output) | |
| 489 | |
| 490 def handle_rest(self): | |
| 491 # Pull the parameters data out of the form. The "value" attribute | |
| 492 # will be the raw content of the request. | |
| 493 input = self.form.value | |
| 494 | |
| 495 # Set the charset and language | |
| 496 self.determine_charset() | |
| 497 self.determine_language() | |
| 498 # Open the database as the correct user. | |
| 499 # TODO: add everything to RestfulDispatcher | |
| 500 self.determine_user() | |
| 501 self.check_anonymous_access() | |
| 502 | |
| 503 # Call rest library to handle the request | |
| 504 handler = rest.RestfulInstance(self.db) | |
| 505 output = handler.dispatch(self.env['REQUEST_METHOD'], self.path, input) | |
| 506 | |
| 507 # self.setHeader("Content-Type", "text/xml") | |
| 484 self.setHeader("Content-Length", str(len(output))) | 508 self.setHeader("Content-Length", str(len(output))) |
| 485 self.write(output) | 509 self.write(output) |
| 486 | 510 |
| 487 def add_ok_message(self, msg, escape=True): | 511 def add_ok_message(self, msg, escape=True): |
| 488 add_message(self._ok_message, msg, escape) | 512 add_message(self._ok_message, msg, escape) |
| 1352 except KeyError: | 1376 except KeyError: |
| 1353 raise NotFound('%s/%s'%(self.classname, self.nodeid)) | 1377 raise NotFound('%s/%s'%(self.classname, self.nodeid)) |
| 1354 if int(self.nodeid) > 2**31: | 1378 if int(self.nodeid) > 2**31: |
| 1355 # Postgres will complain with a ProgrammingError | 1379 # Postgres will complain with a ProgrammingError |
| 1356 # if we try to pass in numbers that are too large | 1380 # if we try to pass in numbers that are too large |
| 1357 raise NotFound ('%s/%s'%(self.classname, self.nodeid)) | 1381 raise NotFound('%s/%s'%(self.classname, self.nodeid)) |
| 1358 if not klass.hasnode(self.nodeid): | 1382 if not klass.hasnode(self.nodeid): |
| 1359 raise NotFound('%s/%s'%(self.classname, self.nodeid)) | 1383 raise NotFound('%s/%s'%(self.classname, self.nodeid)) |
| 1360 # with a designator, we default to item view | 1384 # with a designator, we default to item view |
| 1361 self.template = 'item' | 1385 self.template = 'item' |
| 1362 else: | 1386 else: |
