Skip to content

Commit 91bfaf5

Browse files
committed
content negotiation try/except
1 parent f9babc0 commit 91bfaf5

File tree

2 files changed

+47
-34
lines changed

2 files changed

+47
-34
lines changed

lib/bald/__init__.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,15 @@ def __getitem__(self, item):
235235
if not self.is_http_uri(item):
236236
raise ValueError('{} is not a HTTP URI.'.format(item))
237237
if item not in self.cache:
238-
headers = {'Accept': 'application/rdf+xml, text/html'}
239238
# import datetime
240239
# now = datetime.datetime.utcnow()
241240
# print('\ndownloading: {}'.format(item))
242-
self.cache[item] = requests.get(item, headers=headers)
241+
try:
242+
headers = {'Accept': 'application/rdf+xml'}
243+
self.cache[item] = requests.get(item, headers=headers)
244+
except Exception:
245+
headers = {'Accept': 'text/html'}
246+
self.cache[item] = requests.get(item, headers=headers)
243247
# then = datetime.datetime.utcnow()
244248
# print('{}s'.format((then-now).total_seconds()))
245249

@@ -696,10 +700,15 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
696700

697701
for alias in aliases:
698702
response = cache[aliases[alias]]
699-
try:
700-
aliasgraph.parse(data=response.text, format='xml')
701-
except TypeError:
702-
pass
703+
aliasgraph.parse(data=response.text, format='xml')
704+
# try:
705+
# import xml.sax._exceptions
706+
# aliasgraph.parse(data=response.text, format='xml')
707+
# except TypeError:
708+
# pass
709+
# except xml.sax._exceptions.SAXParseException:
710+
# import pdb; pdb.set_trace()
711+
# pass
703712
# if hasattr(fhandle, 'Conventions'):
704713
# conventions = [c.strip() for c in fhandle.Conventions.split(',')]
705714
# for conv in conventions:
@@ -751,7 +760,11 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
751760

752761
reference_prefixes = dict()
753762
reference_graph = copy.copy(aliasgraph)
754-
reference_graph.parse('http://binary-array-ld.net/latest?_format=ttl')
763+
764+
response = cache['http://binary-array-ld.net/latest']
765+
reference_graph.parse(data=response.text, format='xml')
766+
767+
# reference_graph.parse('http://binary-array-ld.net/latest?_format=ttl')
755768
qstr = ('prefix bald: <http://binary-array-ld.net/latest/> '
756769
'prefix skos: <http://www.w3.org/2004/02/skos/core#> '
757770
'select ?s '

lib/bald/tests/integration/HTML/hdf_container_nest.html

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -174,33 +174,33 @@
174174
return cell;
175175
};
176176

177-
var file:///tmp/tmp9cq2_b_a.hdf/alocation = instance('file:///tmp/tmp9cq2_b_a.hdf/alocation:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>, <a xlink:href="http://binary-array-ld.net/latest/Reference" xlink:show=new text-decoration="underline">bald__Reference</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 11, 17'], '#878800');
178-
var file:///tmp/tmp9cq2_b_a.hdf/anotherpair = instance('file:///tmp/tmp9cq2_b_a.hdf/anotherpair:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>, <a xlink:href="http://binary-array-ld.net/latest/Reference" xlink:show=new text-decoration="underline">bald__Reference</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 2'], '#878800');
179-
var file:///tmp/tmp9cq2_b_a.hdf/apair = instance('file:///tmp/tmp9cq2_b_a.hdf/apair:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 2'], '#878800');
180-
var file:///tmp/tmp9cq2_b_a.hdf/data = instance('file:///tmp/tmp9cq2_b_a.hdf/data:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 11, 17'], '#878800');
181-
var file:///tmp/tmp9cq2_b_a.hdf/discovery = instance('file:///tmp/tmp9cq2_b_a.hdf/discovery:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
182-
var file:///tmp/tmp9cq2_b_a.hdf/institution = instance('file:///tmp/tmp9cq2_b_a.hdf/institution:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: |', '<a xlink:href="http://www.w3.org/2004/02/skos/core#prefLabel" xlink:show=new text-decoration="underline">skos__prefLabel</a>: a quality establishment'], '#878800');
183-
var file:///tmp/tmp9cq2_b_a.hdf/locref = instance('file:///tmp/tmp9cq2_b_a.hdf/locref:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: |', '<a xlink:href="http://www.w3.org/2004/02/skos/core#prefLabel" xlink:show=new text-decoration="underline">skos__prefLabel</a>: for locational purposes'], '#878800');
184-
var file:///tmp/tmp9cq2_b_a.hdf/locref2 = instance('file:///tmp/tmp9cq2_b_a.hdf/locref2:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: |', '<a xlink:href="http://www.w3.org/2004/02/skos/core#prefLabel" xlink:show=new text-decoration="underline">skos__prefLabel</a>: for more locational purposes'], '#878800');
185-
var file:///tmp/tmp9cq2_b_a.hdf/referencing = instance('file:///tmp/tmp9cq2_b_a.hdf/referencing:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
186-
var file:///tmp/tmp9cq2_b_a.hdf/root = instance('file:///tmp/tmp9cq2_b_a.hdf/root:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
187-
var file:///tmp/tmp9cq2_b_a.hdf/source = instance('file:///tmp/tmp9cq2_b_a.hdf/source:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
188-
link(file:///tmp/tmp9cq2_b_a.hdf/alocation, file:///tmp/tmp9cq2_b_a.hdf/alocation, 'bald__array', 'bottom');
189-
link(file:///tmp/tmp9cq2_b_a.hdf/alocation, file:///tmp/tmp9cq2_b_a.hdf/locref, 'bald__references');
190-
link(file:///tmp/tmp9cq2_b_a.hdf/alocation, file:///tmp/tmp9cq2_b_a.hdf/locref2, 'bald__references');
191-
link(file:///tmp/tmp9cq2_b_a.hdf/anotherpair, file:///tmp/tmp9cq2_b_a.hdf/anotherpair, 'bald__array', 'bottom');
192-
link(file:///tmp/tmp9cq2_b_a.hdf/apair, file:///tmp/tmp9cq2_b_a.hdf/anotherpair, 'bald__references');
193-
link(file:///tmp/tmp9cq2_b_a.hdf/data, file:///tmp/tmp9cq2_b_a.hdf/alocation, 'bald__references');
194-
link(file:///tmp/tmp9cq2_b_a.hdf/discovery, file:///tmp/tmp9cq2_b_a.hdf/anotherpair, 'bald__contains', 'top', true);
195-
link(file:///tmp/tmp9cq2_b_a.hdf/discovery, file:///tmp/tmp9cq2_b_a.hdf/apair, 'bald__contains', 'top', true);
196-
link(file:///tmp/tmp9cq2_b_a.hdf/discovery, file:///tmp/tmp9cq2_b_a.hdf/source, 'bald__contains', 'top', true);
197-
link(file:///tmp/tmp9cq2_b_a.hdf/referencing, file:///tmp/tmp9cq2_b_a.hdf/locref, 'bald__contains', 'top', true);
198-
link(file:///tmp/tmp9cq2_b_a.hdf/referencing, file:///tmp/tmp9cq2_b_a.hdf/locref2, 'bald__contains', 'top', true);
199-
link(file:///tmp/tmp9cq2_b_a.hdf/root, file:///tmp/tmp9cq2_b_a.hdf/alocation, 'bald__contains', 'top', true);
200-
link(file:///tmp/tmp9cq2_b_a.hdf/root, file:///tmp/tmp9cq2_b_a.hdf/data, 'bald__contains', 'top', true);
201-
link(file:///tmp/tmp9cq2_b_a.hdf/root, file:///tmp/tmp9cq2_b_a.hdf/discovery, 'bald__contains', 'top', true);
202-
link(file:///tmp/tmp9cq2_b_a.hdf/root, file:///tmp/tmp9cq2_b_a.hdf/referencing, 'bald__contains', 'top', true);
203-
link(file:///tmp/tmp9cq2_b_a.hdf/source, file:///tmp/tmp9cq2_b_a.hdf/institution, 'bald__contains', 'top', true);
177+
var file:///tmp/tmp0ed878yz.hdf/alocation = instance('file:///tmp/tmp0ed878yz.hdf/alocation:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>, <a xlink:href="http://binary-array-ld.net/latest/Reference" xlink:show=new text-decoration="underline">bald__Reference</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 11, 17'], '#878800');
178+
var file:///tmp/tmp0ed878yz.hdf/anotherpair = instance('file:///tmp/tmp0ed878yz.hdf/anotherpair:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>, <a xlink:href="http://binary-array-ld.net/latest/Reference" xlink:show=new text-decoration="underline">bald__Reference</a>', ['<a xlink:href="http://binary-array-ld.net/latest/array" xlink:show=new text-decoration="underline">bald__array</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 2'], '#878800');
179+
var file:///tmp/tmp0ed878yz.hdf/apair = instance('file:///tmp/tmp0ed878yz.hdf/apair:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 2'], '#878800');
180+
var file:///tmp/tmp0ed878yz.hdf/data = instance('file:///tmp/tmp0ed878yz.hdf/data:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/references" xlink:show=new text-decoration="underline">bald__references</a>: |', '<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: 11, 17'], '#878800');
181+
var file:///tmp/tmp0ed878yz.hdf/discovery = instance('file:///tmp/tmp0ed878yz.hdf/discovery:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
182+
var file:///tmp/tmp0ed878yz.hdf/institution = instance('file:///tmp/tmp0ed878yz.hdf/institution:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: |', '<a xlink:href="http://www.w3.org/2004/02/skos/core#prefLabel" xlink:show=new text-decoration="underline">skos__prefLabel</a>: a quality establishment'], '#878800');
183+
var file:///tmp/tmp0ed878yz.hdf/locref = instance('file:///tmp/tmp0ed878yz.hdf/locref:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: |', '<a xlink:href="http://www.w3.org/2004/02/skos/core#prefLabel" xlink:show=new text-decoration="underline">skos__prefLabel</a>: for locational purposes'], '#878800');
184+
var file:///tmp/tmp0ed878yz.hdf/locref2 = instance('file:///tmp/tmp0ed878yz.hdf/locref2:<a xlink:href="http://binary-array-ld.net/latest/Array" xlink:show=new text-decoration="underline">bald__Array</a>', ['<a xlink:href="http://binary-array-ld.net/latest/shape" xlink:show=new text-decoration="underline">bald__shape</a>: |', '<a xlink:href="http://www.w3.org/2004/02/skos/core#prefLabel" xlink:show=new text-decoration="underline">skos__prefLabel</a>: for more locational purposes'], '#878800');
185+
var file:///tmp/tmp0ed878yz.hdf/referencing = instance('file:///tmp/tmp0ed878yz.hdf/referencing:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
186+
var file:///tmp/tmp0ed878yz.hdf/root = instance('file:///tmp/tmp0ed878yz.hdf/root:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
187+
var file:///tmp/tmp0ed878yz.hdf/source = instance('file:///tmp/tmp0ed878yz.hdf/source:<a xlink:href="http://binary-array-ld.net/latest/Container" xlink:show=new text-decoration="underline">bald__Container</a>', ['<a xlink:href="http://binary-array-ld.net/latest/contains" xlink:show=new text-decoration="underline">bald__contains</a>: |'], '#878800');
188+
link(file:///tmp/tmp0ed878yz.hdf/alocation, file:///tmp/tmp0ed878yz.hdf/alocation, 'bald__array', 'bottom');
189+
link(file:///tmp/tmp0ed878yz.hdf/alocation, file:///tmp/tmp0ed878yz.hdf/locref, 'bald__references');
190+
link(file:///tmp/tmp0ed878yz.hdf/alocation, file:///tmp/tmp0ed878yz.hdf/locref2, 'bald__references');
191+
link(file:///tmp/tmp0ed878yz.hdf/anotherpair, file:///tmp/tmp0ed878yz.hdf/anotherpair, 'bald__array', 'bottom');
192+
link(file:///tmp/tmp0ed878yz.hdf/apair, file:///tmp/tmp0ed878yz.hdf/anotherpair, 'bald__references');
193+
link(file:///tmp/tmp0ed878yz.hdf/data, file:///tmp/tmp0ed878yz.hdf/alocation, 'bald__references');
194+
link(file:///tmp/tmp0ed878yz.hdf/discovery, file:///tmp/tmp0ed878yz.hdf/anotherpair, 'bald__contains', 'top', true);
195+
link(file:///tmp/tmp0ed878yz.hdf/discovery, file:///tmp/tmp0ed878yz.hdf/apair, 'bald__contains', 'top', true);
196+
link(file:///tmp/tmp0ed878yz.hdf/discovery, file:///tmp/tmp0ed878yz.hdf/source, 'bald__contains', 'top', true);
197+
link(file:///tmp/tmp0ed878yz.hdf/referencing, file:///tmp/tmp0ed878yz.hdf/locref, 'bald__contains', 'top', true);
198+
link(file:///tmp/tmp0ed878yz.hdf/referencing, file:///tmp/tmp0ed878yz.hdf/locref2, 'bald__contains', 'top', true);
199+
link(file:///tmp/tmp0ed878yz.hdf/root, file:///tmp/tmp0ed878yz.hdf/alocation, 'bald__contains', 'top', true);
200+
link(file:///tmp/tmp0ed878yz.hdf/root, file:///tmp/tmp0ed878yz.hdf/data, 'bald__contains', 'top', true);
201+
link(file:///tmp/tmp0ed878yz.hdf/root, file:///tmp/tmp0ed878yz.hdf/discovery, 'bald__contains', 'top', true);
202+
link(file:///tmp/tmp0ed878yz.hdf/root, file:///tmp/tmp0ed878yz.hdf/referencing, 'bald__contains', 'top', true);
203+
link(file:///tmp/tmp0ed878yz.hdf/source, file:///tmp/tmp0ed878yz.hdf/institution, 'bald__contains', 'top', true);
204204
joint.layout.DirectedGraph.layout(graph, { setLinkVertices: false,
205205
nodeSep: 150, rankSep: 100,
206206
marginX: 100, marginY: 100,

0 commit comments

Comments
 (0)