summaryrefslogtreecommitdiff
path: root/snapmesh_plain.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2015-02-21 16:27:24 +0100
committerTimo <Code-WvS@quantentunnel.de>2015-02-21 16:27:24 +0100
commit40f499401313ebcd9f1d679ed61954b306f738f3 (patch)
tree4cd444213b48fea088ae061c9f2f0cb8056afac2 /snapmesh_plain.py
downloadsnapmesh-40f499401313ebcd9f1d679ed61954b306f738f3.tar.gz
snapmesh-40f499401313ebcd9f1d679ed61954b306f738f3.zip
first commit
Diffstat (limited to 'snapmesh_plain.py')
-rwxr-xr-xsnapmesh_plain.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/snapmesh_plain.py b/snapmesh_plain.py
new file mode 100755
index 0000000..f89eebf
--- /dev/null
+++ b/snapmesh_plain.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python2
+#Snap! extension base by Technoboy10
+#features by Timo
+
+data = dict()
+
+import SimpleHTTPServer
+class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
+ def send_head(self):
+ path = self.path
+ ospath = os.path.abspath('')
+ if '/put' in path:
+ regex = re.compile("\/put\?value=(.*?)&key=(.*)")
+ m = regex.match(path)
+ value = urllib2.unquote(m.group(1))
+ key = urllib2.unquote(m.group(2))
+ data[key] = value
+ return
+
+ if '/check' in path:
+ regex = re.compile("\/check\?key=(.*)")
+ m = regex.match(path)
+ key = urllib2.unquote(m.group(1))
+ f = open(ospath + '/return', 'w+')
+ f.write(str(key in data))
+ f.close()
+ if '/get' in path:
+ regex = re.compile("\/get\?key=(.*)")
+ m = regex.match(path)
+ key = urllib2.unquote(m.group(1))
+ if not key in data:
+ return ''
+
+ f = open(ospath + '/return', 'w+')
+ f.write(str(data[key]))
+ f.close()
+ if '/list' in path:
+ f = open(ospath + '/return', 'w+')
+ f.write(data.keys().join('\n'))
+ f.close()
+
+ f = open(ospath + '/return', 'rb')
+ ctype = self.guess_type(ospath + '/return')
+ self.send_response(200)
+ self.send_header("Content-type", ctype)
+ fs = os.fstat(f.fileno())
+ self.send_header("Content-Length", str(fs[6]))
+ self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
+ self.send_header("Access-Control-Allow-Origin", "*")
+ self.end_headers()
+ return f
+
+if __name__ == "__main__":
+ import os
+ import re
+ import SocketServer
+ import urllib2
+ PORT = 9876 #Pick a port number
+
+ Handler = CORSHTTPRequestHandler
+ httpd = SocketServer.TCPServer(("", PORT), Handler)
+ httpd.serve_forever()