annotate service/reasoning/rdflibtrig.py @ 1045:a328cc370b22

ipv6 fetch support. refactor Actions to new class and file Ignore-this: 200d7093919cf001706ad9c02347fabb darcs-hash:176d0511a0f5f4b9dab9317103c2b095196326fb
author drewp <drewp@bigasterisk.com>
date Mon, 01 Feb 2016 03:28:17 -0800
parents 2fa7daf06f34
children e5c27d2f11ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1045
a328cc370b22 ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents: 1040
diff changeset
1 import time
a328cc370b22 ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents: 1040
diff changeset
2 import requests
1040
2fa7daf06f34 rdflib can parse trig now
drewp <drewp@bigasterisk.com>
parents: 934
diff changeset
3 from rdflib import ConjunctiveGraph
919
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
4
934
3bb18b7d21df reasoning actions: generalize them a bit but then add a bunch of special cases for mpd for now
drewp <drewp@bigasterisk.com>
parents: 923
diff changeset
5 def addTrig(graph, url, timeout=2):
919
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
6 t1 = time.time()
1045
a328cc370b22 ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents: 1040
diff changeset
7 response = requests.get(url, stream=True, timeout=timeout)
a328cc370b22 ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents: 1040
diff changeset
8 if response.status_code != 200:
923
4ae49c6adecb errors and logging in reasoning
drewp <drewp@bigasterisk.com>
parents: 919
diff changeset
9 raise ValueError("status %s from %s" % (response.status, url))
1045
a328cc370b22 ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents: 1040
diff changeset
10 g = ConjunctiveGraph()
a328cc370b22 ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents: 1040
diff changeset
11 g.parse(response.raw, format='trig')
919
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
12 fetchTime = time.time() - t1
1040
2fa7daf06f34 rdflib can parse trig now
drewp <drewp@bigasterisk.com>
parents: 934
diff changeset
13 graph.addN(g.quads())
919
6ee2a90fc816 bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
drewp <drewp@bigasterisk.com>
parents:
diff changeset
14 return fetchTime