aboutsummaryrefslogtreecommitdiff
path: root/bvggrabber/utils/json.py
diff options
context:
space:
mode:
authorChristian Struck <christian@struck.se>2013-02-04 21:16:12 +0100
committerChristian Struck <christian@struck.se>2013-02-04 21:16:12 +0100
commit1ede09d2c27066f161e65aec0a309c9cdc32a54b (patch)
tree14ae6defb41af13b8abad77059f2ca486d426b9f /bvggrabber/utils/json.py
parente1981063359b0910614e5ea3f861a5ce1e54970d (diff)
downloadbvg-grabber-1ede09d2c27066f161e65aec0a309c9cdc32a54b.tar.gz
bvg-grabber-1ede09d2c27066f161e65aec0a309c9cdc32a54b.tar.bz2
bvg-grabber-1ede09d2c27066f161e65aec0a309c9cdc32a54b.zip
made Response object json serializable reworked tests and removed to_json from departure object
Diffstat (limited to 'bvggrabber/utils/json.py')
-rw-r--r--bvggrabber/utils/json.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/bvggrabber/utils/json.py b/bvggrabber/utils/json.py
new file mode 100644
index 0000000..d5bec53
--- /dev/null
+++ b/bvggrabber/utils/json.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+
+import inspect
+
+from json import JSONEncoder
+
+
+def is_not_method(o):
+ return not inspect.isroutine(o)
+
+
+class ObjectJSONEncoder(JSONEncoder):
+
+ def default(self, reject):
+ non_methods = inspect.getmembers(reject, is_not_method)
+ return {attr: value for attr, value in non_methods
+ if (not attr.startswith('__')
+ and attr != 'when'
+ and attr != 'now')}