diff lib/patchablegraph/browser_test.py @ 710:94610b5263e4

add browser_test server for playing with /graph resource Ignore-this: 6112c234b93e0fb99ffe918a022e5a49
author drewp@bigasterisk.com
date Mon, 03 Feb 2020 23:45:15 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/patchablegraph/browser_test.py	Mon Feb 03 23:45:15 2020 -0800
@@ -0,0 +1,33 @@
+"""
+see how a browser talks to this PatchableGraph
+"""
+
+from rdflib import Namespace, Literal, ConjunctiveGraph, URIRef, RDF
+from twisted.internet import reactor
+import cyclone.web
+
+from standardservice.logsetup import log, verboseLogging
+from patchablegraph import PatchableGraph, CycloneGraphEventsHandler, CycloneGraphHandler
+
+verboseLogging(True)
+
+graph = PatchableGraph()
+g = ConjunctiveGraph()
+g.add((URIRef('http://example.com/s'),
+       URIRef('http://example.com/p'),
+       URIRef('http://example.com/o'),
+       URIRef('http://example.com/g')))
+graph.setToGraph(g)
+
+class Application(cyclone.web.Application):
+    def __init__(self):
+        handlers = [
+            (r'/graph', CycloneGraphHandler, {'masterGraph': graph}),
+            (r'/graph/events', CycloneGraphEventsHandler,
+             {'masterGraph': graph}),
+        ]
+        cyclone.web.Application.__init__(self, handlers)
+
+
+reactor.listenTCP(8021, Application())
+reactor.run()