|
19 | 19 | import traceback |
20 | 20 | import re |
21 | 21 |
|
| 22 | +try: |
| 23 | + from dicttoxml import dicttoxml |
| 24 | +except ImportError: |
| 25 | + dicttoxml = None |
| 26 | + |
22 | 27 | from roundup import hyperdb |
23 | 28 | from roundup import date |
24 | 29 | from roundup import actions |
@@ -305,8 +310,8 @@ class RestfulInstance(object): |
305 | 310 | __default_patch_op = "replace" # default operator for PATCH method |
306 | 311 | __accepted_content_type = { |
307 | 312 | "application/json": "json", |
308 | | - "*/*": "json" |
309 | | - # "application/xml": "xml" |
| 313 | + "*/*": "json", |
| 314 | + "application/xml": "xml" |
310 | 315 | } |
311 | 316 | __default_accept_type = "json" |
312 | 317 |
|
@@ -620,7 +625,7 @@ def get_attribute(self, class_name, item_id, attr_name, input): |
620 | 625 | data = node.__getattr__(attr_name) |
621 | 626 | result = { |
622 | 627 | 'id': item_id, |
623 | | - 'type': type(data), |
| 628 | + 'type': str(type(data)), |
624 | 629 | 'link': "%s/%s/%s/%s" % |
625 | 630 | (self.data_path, class_name, item_id, attr_name), |
626 | 631 | 'data': data, |
@@ -1303,6 +1308,9 @@ def dispatch(self, method, uri, input): |
1303 | 1308 | else: |
1304 | 1309 | indent = None |
1305 | 1310 | output = RoundupJSONEncoder(indent=indent).encode(output) |
| 1311 | + elif data_type.lower() == "xml" and dicttoxml: |
| 1312 | + self.client.setHeader("Content-Type", "application/xml") |
| 1313 | + output = dicttoxml(output, root=False) |
1306 | 1314 | else: |
1307 | 1315 | self.client.response_code = 406 |
1308 | 1316 | output = "Content type is not accepted by client" |
|
0 commit comments