[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [oonib/master] Add NetTest API



commit 45a5ddb9eb7388976c5c7e09b5ca553681b6b46f
Author: aagbsn <aagbsn@xxxxxxxx>
Date:   Sun Aug 18 23:41:41 2013 +0200

    Add NetTest API
---
 oonib/nettest/api.py      |   10 ++++++++++
 oonib/nettest/handlers.py |   25 +++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/oonib/nettest/api.py b/oonib/nettest/api.py
new file mode 100644
index 0000000..758b31d
--- /dev/null
+++ b/oonib/nettest/api.py
@@ -0,0 +1,10 @@
+from cyclone import web
+from oonib.nettest import handlers
+from oonib import config
+
+nettestAPI = [
+    (r"/nettest", handlers.NetTestListHandler),
+    (r"/nettest/([a-f0-9]{64})", handlers.NetTestDescHandler),
+    (r"/nettest/([a-f0-9]{64})/py$", web.StaticFileHandler, {"path":
+        config.main.nettest_dir}),
+]
diff --git a/oonib/nettest/handlers.py b/oonib/nettest/handlers.py
new file mode 100644
index 0000000..17d5590
--- /dev/null
+++ b/oonib/nettest/handlers.py
@@ -0,0 +1,25 @@
+import glob
+import json
+import os
+import yaml
+
+from oonib.handlers import OONIBHandler
+from oonib import config, log
+
+class NetTestDescHandler(OONIBHandler):
+    def get(self, netTestID):
+        bn = os.path.basename(netTestID) + ".desc"
+        try:
+            f = open(os.path.join(config.main.nettest_dir, bn))
+            a = {}
+            netTestDesc = yaml.safe_load(f)
+            for k in ['name', 'description', 'version', 'author', 'date']:
+                a[k] = netTestDesc[k]
+            self.write(json.dumps(a))
+        except IOError:
+            log.err("No NetTest Descriptor found for id %s" % netTestID) 
+        except Exception, e:
+            log.err("Invalid NetTest Descriptor found for id %s" % netTestID) 
+
+
+



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits