Mercurial > p > roundup > code
diff roundup/rest.py @ 5560:2cc07def1b3f REST-rebased
use getattr instead of calling each function
committer: Ralf Schlatterbeck <rsc@runtux.com>
| author | Chau Nguyen <dangchau1991@yahoo.com> |
|---|---|
| date | Wed, 30 Jan 2019 10:26:33 +0100 |
| parents | 3d80e7752783 |
| children | 7aa7f779198b |
line wrap: on
line diff
--- a/roundup/rest.py Wed Jan 30 10:25:12 2019 +0100 +++ b/roundup/rest.py Wed Jan 30 10:26:33 2019 +0100 @@ -98,6 +98,7 @@ def action_delete(self, resource_uri, input): # TODO: should I allow user to delete the whole collection ? # TODO: BUG with DELETE without form data. Working with random data + # crash at line self.form = cgi.FieldStorage(fp=request.rfile, environ=env) class_name = resource_uri try: class_obj = self.db.getclass(class_name) @@ -136,24 +137,14 @@ input_form = ["%s=%s" % (item.name, item.value) for item in input] # TODO: process input_form directly instead of making a new array # TODO: rest server - # TODO: use named function for this instead # TODO: check roundup/actions.py # TODO: if uri_path has more than 2 child, return 404 # TODO: custom JSONEncoder to handle other data type # TODO: catch all error and display error. - output = "METHOD is not supported" - if method == "GET": - output = self.action_get(uri_path[1], input_form) - elif method == "POST": - output = self.action_post(uri_path[1], input_form) - elif method == "PUT": - output = self.action_put(uri_path[1], input_form) - elif method == "DELETE": - output = self.action_delete(uri_path[1], input_form) - elif method == "PATCH": - output = self.action_patch(uri_path[1], input_form) - else: - pass + try: + output = getattr(self, "action_%s" % method.lower())(uri_path[1], input_form) + except AttributeError: + raise NotImplementedError print "Response Length: %s - Response Content (First 50 char): %s" %\ (len(output), output[:50])
