comparison service/reasoning/patchsource.py @ 1117:d5687ba23279

fix input graph web display by dirtying combinedGraph better. Ignore-this: e40e7499e3d675b029f829a1f269b83a darcs-hash:c15a1820ca7b5e40b2a27946bfe1c87cc80612fa
author drewp <drewp@bigasterisk.com>
date Sun, 09 Oct 2016 13:57:50 -0700
parents aa70001ea0c9
children
comparison
equal deleted inserted replaced
1116:d22c0c502ff6 1117:d5687ba23279
1 import sys 1 import sys, logging
2 import traceback 2 import traceback
3 from twisted.internet import reactor, defer 3 from twisted.internet import reactor, defer
4 from twisted_sse_demo.eventsource import EventSource 4 from twisted_sse_demo.eventsource import EventSource
5 from rdflib import ConjunctiveGraph 5 from rdflib import ConjunctiveGraph
6 from rdflib.parser import StringInputSource 6 from rdflib.parser import StringInputSource
7 7
8 sys.path.append("../../lib") 8 sys.path.append("../../lib")
9 from logsetup import log
10 from patchablegraph import patchFromJson 9 from patchablegraph import patchFromJson
11 10
12 sys.path.append("/my/proj/light9") 11 sys.path.append("/my/proj/light9")
13 from light9.rdfdb.patch import Patch 12 from light9.rdfdb.patch import Patch
14 13
14 log = logging.getLogger('fetch')
15 15
16 class PatchSource(object): 16 class PatchSource(object):
17 """wrap EventSource so it emits Patch objects and has an explicit stop method.""" 17 """wrap EventSource so it emits Patch objects and has an explicit stop method."""
18 def __init__(self, url): 18 def __init__(self, url):
19 self.url = url 19 self.url = url
23 self.connectionFailed = defer.Deferred() 23 self.connectionFailed = defer.Deferred()
24 self.connectionLost = defer.Deferred() 24 self.connectionLost = defer.Deferred()
25 25
26 self._listeners = set() 26 self._listeners = set()
27 log.info('start read from %s', url) 27 log.info('start read from %s', url)
28 # note: fullGraphReceived isn't guaranteed- the stream could
29 # start with patches
28 self._fullGraphReceived = False 30 self._fullGraphReceived = False
29 self._eventSource = EventSource(url.toPython().encode('utf8')) 31 self._eventSource = EventSource(url.toPython().encode('utf8'))
30 self._eventSource.protocol.delimiter = '\n' 32 self._eventSource.protocol.delimiter = '\n'
31 33
32 self._eventSource.addEventListener('fullGraph', self._onFullGraph) 34 self._eventSource.addEventListener('fullGraph', self._onFullGraph)