Mercurial > p > roundup > code
diff roundup/rest.py @ 5631:a5c890d308c3
Add simple support for xml output if the third party dict2xml.py module
https://pypi.org/project/dict2xml/
is installed.
Also this checkin adds the ETag support comment to the CHANGES
document. The file was accidently omitted from the rest of the etag
checkin.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 01 Mar 2019 23:16:13 -0500 |
| parents | 07abc8d36940 |
| children | a29a8dae2095 |
line wrap: on
line diff
--- a/roundup/rest.py Fri Mar 01 22:57:07 2019 -0500 +++ b/roundup/rest.py Fri Mar 01 23:16:13 2019 -0500 @@ -19,6 +19,11 @@ import traceback import re +try: + from dicttoxml import dicttoxml +except ImportError: + dicttoxml = None + from roundup import hyperdb from roundup import date from roundup import actions @@ -305,8 +310,8 @@ __default_patch_op = "replace" # default operator for PATCH method __accepted_content_type = { "application/json": "json", - "*/*": "json" - # "application/xml": "xml" + "*/*": "json", + "application/xml": "xml" } __default_accept_type = "json" @@ -620,7 +625,7 @@ data = node.__getattr__(attr_name) result = { 'id': item_id, - 'type': type(data), + 'type': str(type(data)), 'link': "%s/%s/%s/%s" % (self.data_path, class_name, item_id, attr_name), 'data': data, @@ -1303,6 +1308,9 @@ else: indent = None output = RoundupJSONEncoder(indent=indent).encode(output) + elif data_type.lower() == "xml" and dicttoxml: + self.client.setHeader("Content-Type", "application/xml") + output = dicttoxml(output, root=False) else: self.client.response_code = 406 output = "Content type is not accepted by client"
