Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a hook to add custom functions to SPARQL #723

Merged
merged 4 commits into from
May 29, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions rdflib/plugins/sparql/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,21 @@ def Function(e, ctx):
Custom functions and casts
"""
pair =_CUSTOM_FUNCTIONS.get(e.iri)
if pair is not None:
func, raw = pair
if raw:
return func(e, ctx)
else:
try:
return func(*e.expr)
except TypeError as ex:
raise SPARQLError(*ex.args)
if pair is None:
# no such function is registered
raise SPARQLError('Unknown function %r"%e.iri')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think what you actually want is raise SPARQLError('Unknown function %r' % e.iri)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what the... :-/ well spotted !

func, raw = pair
if raw:
# function expects expression and context
return func(e, ctx)
else:
raise SPARQLError('Unknown function %r"%e.iri')
# function expects the argument list
try:
return func(*e.expr)
except TypeError as ex:
# wrong argument number
raise SPARQLError(*ex.args)



@custom_function(XSD.string, raw=True)
Expand Down