[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [oonib/master] Add support for serializing lists to json via self.write()
commit 1e0d3c0d0b20f92fd901163a4f2b41627f9e931e
Author: Arturo Filastò <art@xxxxxxxxx>
Date: Mon Aug 19 14:03:42 2013 +0200
Add support for serializing lists to json via self.write()
---
oonib/handlers.py | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/oonib/handlers.py b/oonib/handlers.py
index 62496ce..515e8c2 100644
--- a/oonib/handlers.py
+++ b/oonib/handlers.py
@@ -1,7 +1,20 @@
+import types
+
+from cyclone import escape
from cyclone import web
class OONIBHandler(web.RequestHandler):
- pass
+ def write(self, chunk):
+ """
+ This is a monkey patch to RequestHandler to allow us to serialize also
+ json list objects.
+ """
+ if isinstance(chunk, types.ListType):
+ chunk = escape.json_encode(chunk)
+ web.RequestHandler.write(self, chunk)
+ self.set_header("Content-Type", "application/json")
+ else:
+ web.RequestHandler.write(self, chunk)
class OONIBError(web.HTTPError):
pass
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits