Skip to content

Commit 1a4997f

Browse files
committed
prefer python3
1 parent ca4a69d commit 1a4997f

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: python
22
python:
3-
- "2.7"
3+
- "3.5"
44
install:
55
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
66
- bash Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/miniconda

lib/bald/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
import rdflib
99
import requests
10+
import six
1011

1112
import bald.validation as bv
1213

@@ -214,7 +215,7 @@ def _network_js_close():
214215

215216

216217
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://'))
218219

219220

220221
class HttpCache(object):
@@ -225,7 +226,7 @@ def __init__(self):
225226
self.cache = {}
226227

227228
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://'))
229230

230231
def __getitem__(self, item):
231232

@@ -291,7 +292,7 @@ def __setattr__(self, attr, value):
291292
self.attrs[attr].add(value)
292293
else:
293294
self.attrs[attr] = set((self.attrs[attr], value))
294-
elif isinstance(self.attrs[attr], basestring):
295+
elif isinstance(self.attrs[attr], six.string_types):
295296
self.attrs[attr] = set([self.attrs[attr]])
296297

297298

@@ -303,7 +304,7 @@ def __getattr__(self, attr):
303304

304305
def prefixes(self):
305306
prefixes = {}
306-
for key, value in self._prefixes.iteritems():
307+
for key, value in self._prefixes.items():
307308
if key.endswith('__') and self._http_uri_prefix.match(value):
308309
pref = key.rstrip('__')
309310
if pref in prefixes:
@@ -319,13 +320,13 @@ def unpack_uri(self, astring):
319320
320321
"""
321322
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):
323324
prefix, suffix = self._prefix_suffix.match(astring).groups()
324325
if prefix in self.prefixes():
325326
if self._http_uri.match(self.prefixes()[prefix]):
326327
result = astring.replace('{}__'.format(prefix),
327328
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:
329330
result = self.aliases[astring]
330331
return result
331332

@@ -356,7 +357,7 @@ def _graph_elem_attrs(self, remaining_attrs):
356357
else:
357358
kstr = '{key}: '.format(key=attr)
358359
vals = remaining_attrs[attr]
359-
if isinstance(vals, basestring):
360+
if isinstance(vals, six.string_types):
360361
if is_http_uri(self.unpack_uri(vals)):
361362
vstr = self.link_template
362363
vstr = vstr.format(url=self.unpack_uri(vals), key=vals)
@@ -376,6 +377,7 @@ def _graph_elem_attrs(self, remaining_attrs):
376377
vstrlist.append(vstr)
377378
if vstrlist == []:
378379
vstrlist = ['|']
380+
vstrlist.sort()
379381
vstr = ', '.join(vstrlist)
380382

381383
attrs.append("'{}'".format(kstr + vstr))
@@ -386,6 +388,7 @@ def _graph_elem_attrs(self, remaining_attrs):
386388
type_links = []
387389
for rdftype in self.rdf__type:
388390
type_links.append(atype.format(url=self.unpack_uri(rdftype), key=rdftype))
391+
type_links.sort()
389392
avar = avar.format(var=self.identity, type=', '.join(type_links), attrs=attrs)
390393

391394
return avar

lib/bald/tests/integration/test_cdl_rdfgraph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_array_reference(self):
1818
cdl_file = os.path.join(self.cdl_path, 'array_reference.cdl')
1919
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
2020
root_container = bald.load_netcdf(tfile)
21-
ttl = root_container.rdfgraph().serialize(format='n3')
21+
ttl = root_container.rdfgraph().serialize(format='n3').decode("utf-8")
2222
# with open(os.path.join(self.ttl_path, 'array_reference.ttl'), 'w') as sf:
2323
# sf.write(ttl)
2424
with open(os.path.join(self.ttl_path, 'array_reference.ttl'), 'r') as sf:
@@ -30,7 +30,7 @@ def test_multi_array_reference(self):
3030
cdl_file = os.path.join(self.cdl_path, 'multi_array_reference.cdl')
3131
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
3232
root_container = bald.load_netcdf(tfile)
33-
ttl = root_container.rdfgraph().serialize(format='n3')
33+
ttl = root_container.rdfgraph().serialize(format='n3').decode("utf-8")
3434
# with open(os.path.join(self.ttl_path, 'multi_array_reference.ttl'), 'w') as sf:
3535
# sf.write(ttl)
3636
with open(os.path.join(self.ttl_path, 'multi_array_reference.ttl'), 'r') as sf:

lib/bald/validation.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import rdflib
3+
import six
34

45
import bald
56

@@ -86,25 +87,25 @@ def _check_uri(uri, exceptions):
8687
exceptions.append(msg)
8788
return exceptions
8889

89-
for pref, uri in self.subject.prefixes().iteritems():
90+
for pref, uri in self.subject.prefixes().items():
9091
exceptions = _check_uri(self.subject.unpack_uri(uri),
9192
exceptions)
92-
for alias, uri in self.subject.aliases.iteritems():
93+
for alias, uri in self.subject.aliases.items():
9394
exceptions = _check_uri(self.subject.unpack_uri(uri),
9495
exceptions)
95-
for attr, value in self.subject.attrs.iteritems():
96-
if isinstance(attr, basestring):
96+
for attr, value in self.subject.attrs.items():
97+
if isinstance(attr, six.string_types):
9798
att = self.subject.unpack_uri(attr)
9899
if self.cache.is_http_uri(att):
99100
exceptions = _check_uri(att, exceptions)
100-
if isinstance(value, basestring):
101+
if isinstance(value, six.string_types):
101102
val = self.subject.unpack_uri(value)
102103
if self.cache.is_http_uri(val):
103104
exceptions = _check_uri(val, exceptions)
104105
return exceptions
105106

106107
def check_attr_domain_range(self, exceptions):
107-
for attr, value in self.subject.attrs.iteritems():
108+
for attr, value in self.subject.attrs.items():
108109
uri = self.subject.unpack_uri(attr)
109110
if self.cache.is_http_uri(uri) and self.cache.check_uri(uri):
110111
# thus we have a payload

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ netCDF4
44
requests
55
rdflib
66
jinja2
7+
six

0 commit comments

Comments
 (0)