diff options
author | David Robillard <d@drobilla.net> | 2015-11-23 19:06:45 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2015-11-23 19:06:45 -0500 |
commit | 653c34e4f4cc201faa8332bae7f9fb08f0d09330 (patch) | |
tree | e8e833a10ed8f7e9fe46ad86b9e432b3aa563c39 /scripts/ingen.py | |
parent | c8cbb4f24d2b763530785df79c35cf6f2487fe54 (diff) | |
download | ingen-653c34e4f4cc201faa8332bae7f9fb08f0d09330.tar.gz ingen-653c34e4f4cc201faa8332bae7f9fb08f0d09330.tar.bz2 ingen-653c34e4f4cc201faa8332bae7f9fb08f0d09330.zip |
Fix parsing prefixed names in response stream
Fixes #1054
Diffstat (limited to 'scripts/ingen.py')
-rw-r--r-- | scripts/ingen.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/scripts/ingen.py b/scripts/ingen.py index 8a9c8a2e..594b98cf 100644 --- a/scripts/ingen.py +++ b/scripts/ingen.py @@ -119,6 +119,12 @@ class Remote(Interface): def __del__(self): self.sock.close() + def _get_prefixes_string(self): + s = '' + for k, v in self.ns_manager.namespaces(): + s += '@prefix %s: <%s> .\n' % (k, v) + return s + def msgencode(self, msg): if sys.version_info[0] == 3: return bytes(msg, 'utf-8') @@ -184,9 +190,23 @@ class Remote(Interface): self.sock.send(self.msgencode(msg)) # Receive response and parse into a model - response_str = self.recv() + response_str = self._get_prefixes_string() + self.recv() response_model = rdflib.Graph(namespace_manager=self.ns_manager) - response_model.parse(StringIO(response_str), self.server_base, format='n3') + + # Because rdflib has embarrassingly broken base URI resolution that + # just drops path components from the base URI entirely (seriously), + # unfortunate the real server base URI can not be used here. Use + # <ingen:/> instead to at least avoid complete nonsense + response_model.parse(StringIO(response_str), 'ingen:/', format='n3') + + # Add new prefixes to prepend to future responses because rdflib sucks + for line in response_str.split('\n'): + if line.startswith('@prefix'): + match = re.search('@prefix ([^:]*): <(.*)> *\.', line) + if match: + name = match.group(1) + uri = match.group(2) + self.ns_manager.bind(match.group(1), match.group(2)) # Handle response (though there should be only one) blanks = [] |