7
7
import numpy as np
8
8
import rdflib
9
9
import requests
10
+ import six
10
11
11
12
import bald .validation as bv
12
13
@@ -214,7 +215,7 @@ def _network_js_close():
214
215
215
216
216
217
def is_http_uri (item ):
217
- return isinstance (item , basestring ) and (item .startswith ('http://' ) or item .startswith ('https://' ))
218
+ return isinstance (item , six . string_types ) and (item .startswith ('http://' ) or item .startswith ('https://' ))
218
219
219
220
220
221
class HttpCache (object ):
@@ -225,7 +226,7 @@ def __init__(self):
225
226
self .cache = {}
226
227
227
228
def is_http_uri (self , item ):
228
- return isinstance (item , basestring ) and (item .startswith ('http://' ) or item .startswith ('https://' ))
229
+ return isinstance (item , six . string_types ) and (item .startswith ('http://' ) or item .startswith ('https://' ))
229
230
230
231
def __getitem__ (self , item ):
231
232
@@ -291,7 +292,7 @@ def __setattr__(self, attr, value):
291
292
self .attrs [attr ].add (value )
292
293
else :
293
294
self .attrs [attr ] = set ((self .attrs [attr ], value ))
294
- elif isinstance (self .attrs [attr ], basestring ):
295
+ elif isinstance (self .attrs [attr ], six . string_types ):
295
296
self .attrs [attr ] = set ([self .attrs [attr ]])
296
297
297
298
@@ -303,7 +304,7 @@ def __getattr__(self, attr):
303
304
304
305
def prefixes (self ):
305
306
prefixes = {}
306
- for key , value in self ._prefixes .iteritems ():
307
+ for key , value in self ._prefixes .items ():
307
308
if key .endswith ('__' ) and self ._http_uri_prefix .match (value ):
308
309
pref = key .rstrip ('__' )
309
310
if pref in prefixes :
@@ -319,13 +320,13 @@ def unpack_uri(self, astring):
319
320
320
321
"""
321
322
result = astring
322
- if isinstance (astring , basestring ) and self ._prefix_suffix .match (astring ):
323
+ if isinstance (astring , six . string_types ) and self ._prefix_suffix .match (astring ):
323
324
prefix , suffix = self ._prefix_suffix .match (astring ).groups ()
324
325
if prefix in self .prefixes ():
325
326
if self ._http_uri .match (self .prefixes ()[prefix ]):
326
327
result = astring .replace ('{}__' .format (prefix ),
327
328
self .prefixes ()[prefix ])
328
- elif isinstance (astring , basestring ) and astring in self .aliases :
329
+ elif isinstance (astring , six . string_types ) and astring in self .aliases :
329
330
result = self .aliases [astring ]
330
331
return result
331
332
@@ -356,7 +357,7 @@ def _graph_elem_attrs(self, remaining_attrs):
356
357
else :
357
358
kstr = '{key}: ' .format (key = attr )
358
359
vals = remaining_attrs [attr ]
359
- if isinstance (vals , basestring ):
360
+ if isinstance (vals , six . string_types ):
360
361
if is_http_uri (self .unpack_uri (vals )):
361
362
vstr = self .link_template
362
363
vstr = vstr .format (url = self .unpack_uri (vals ), key = vals )
@@ -376,6 +377,7 @@ def _graph_elem_attrs(self, remaining_attrs):
376
377
vstrlist .append (vstr )
377
378
if vstrlist == []:
378
379
vstrlist = ['|' ]
380
+ vstrlist .sort ()
379
381
vstr = ', ' .join (vstrlist )
380
382
381
383
attrs .append ("'{}'" .format (kstr + vstr ))
@@ -386,6 +388,7 @@ def _graph_elem_attrs(self, remaining_attrs):
386
388
type_links = []
387
389
for rdftype in self .rdf__type :
388
390
type_links .append (atype .format (url = self .unpack_uri (rdftype ), key = rdftype ))
391
+ type_links .sort ()
389
392
avar = avar .format (var = self .identity , type = ', ' .join (type_links ), attrs = attrs )
390
393
391
394
return avar
0 commit comments