Skip to content

Commit

Permalink
Bryon issue 65 & 66 (#67)
Browse files Browse the repository at this point in the history
* fix for #66 - pinning tabulator library to <1.4.1

* fix for #65
  • Loading branch information
bryonjacob authored Oct 8, 2017
1 parent 30c6be5 commit e25da76
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions datadotworld/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import weakref

from datadotworld.config import FileConfig, ChainedConfig
from datadotworld.datadotworld import DataDotWorld
from datadotworld.datadotworld import DataDotWorld, UriParam

__version__ = '1.4.1'
__version__ = '1.4.2'

# Convenience top-level functions

Expand Down
21 changes: 21 additions & 0 deletions datadotworld/datadotworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,25 @@ def open_remote_file(self, dataset_key, file_name,
raise RestApiError(cause=e)


class UriParam():
"""
Represents a URI value as a parameter to a SPARQL query
"""
def __init__(self, uri):
"""
Initialize the UriParam value
:param uri: the uri value to wrap
"""
self._uri = uri

def __repr__(self):
"""
The official string representation for the URI
:return: the string representation for the URI
"""
return self._uri


# convert a literal into the SPARQL format expected by the REST endpoint
def convert_to_sparql_literal(value):
if isinstance(value, bool):
Expand All @@ -292,6 +311,8 @@ def convert_to_sparql_literal(value):
elif isinstance(value, numbers.Number):
return "\"{}\"^^<http://www.w3.org/2001/XMLSchema#decimal>".format(
value)
elif isinstance(value, UriParam):
return "<{}>".format(repr(value))
else:
return "\"{}\"".format(value)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def find_version(*paths):
'python-dateutil>=2.6.0,<3.0a',
'requests>=2.0.0,<3.0a',
'six>=1.5.0,<2.0a',
'tabulator<2.0a',
'tabulator<=1.4.1',
'urllib3>=1.15,<2.0a',
],
setup_requires=[
Expand Down
4 changes: 3 additions & 1 deletion tests/datadotworld/test_datadotworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,14 @@ def test_query_400(self, dw, dataset_key, type, endpoint, query):
'%24data_world_param0%3D%22USA%22'
]
),
('sparql', 'notreallysparql', {'$aString': "USA", '$anInt': 10, '$aDecimal': 100.0, '$aBool': False},
('sparql', 'notreallysparql', {'$aString': "USA", '$anInt': 10, '$aDecimal': 100.0, '$aBool': False,
'$uUri': datadotworld.UriParam('https://example.com/something#something')},
[
'%24anInt%3D%2210%22%5E%5E%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23integer%3E',
'%24aDecimal%3D%22100.0%22%5E%5E%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23decimal%3E',
'%24aString%3D%22USA%22',
'%24aBool%3D%22false%22%5E%5E%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23boolean%3E',
'%3Chttps%3A%2F%2Fexample.com%2Fsomething%23something%3E'
]
)
]
Expand Down

0 comments on commit e25da76

Please sign in to comment.