diff options
Diffstat (limited to 'service/pixelated/resources')
-rw-r--r-- | service/pixelated/resources/__init__.py | 11 | ||||
-rw-r--r-- | service/pixelated/resources/mails_resource.py | 6 |
2 files changed, 14 insertions, 3 deletions
diff --git a/service/pixelated/resources/__init__.py b/service/pixelated/resources/__init__.py index b244900a..c65e19f3 100644 --- a/service/pixelated/resources/__init__.py +++ b/service/pixelated/resources/__init__.py @@ -17,15 +17,22 @@ import json +class SetEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, set): + return list(obj) + return super(SetEncoder, self).default(obj) + + def respond_json(entity, request, status_code=200): - json_response = json.dumps(entity) + json_response = json.dumps(entity, cls=SetEncoder) request.responseHeaders.addRawHeader(b"content-type", b"application/json") request.code = status_code return json_response def respond_json_deferred(entity, request, status_code=200): - json_response = json.dumps(entity) + json_response = json.dumps(entity, cls=SetEncoder) request.responseHeaders.addRawHeader(b"content-type", b"application/json") request.code = status_code request.write(json_response) diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py index d4e8372e..9658bd82 100644 --- a/service/pixelated/resources/mails_resource.py +++ b/service/pixelated/resources/mails_resource.py @@ -123,6 +123,11 @@ class MailsResource(Resource): }) d.addCallback(lambda res: respond_json_deferred(res, request)) + def error_handler(error): + print error + + d.addErrback(error_handler) + return NOT_DONE_YET def render_POST(self, request): @@ -146,7 +151,6 @@ class MailsResource(Resource): return server.NOT_DONE_YET def render_PUT(self, request): - print '\nrender_PUT\n' content_dict = json.loads(request.content.read()) _mail = InputMail.from_dict(content_dict) draft_id = content_dict.get('ident') |