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

Fix/1369 custom resolver #1385

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Allow explicit resolvers to be passed to parsers.
  • Loading branch information
alexdutton committed Aug 4, 2021
commit 90254ec688a164f0c41f2948a505ff3bbdc84d91
12 changes: 9 additions & 3 deletions rdflib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@


class Parser(object):
__slots__ = ()
__slots__ = ("_resolver",)

def __init__(self):
pass
def __init__(self, *, resolver=None):
self._resolver = resolver

@property
def resolver(self):
from .resolver import get_default_resolver

return self._resolver or get_default_resolver()

def parse(self, source, sink):
pass
Expand Down
3 changes: 0 additions & 3 deletions rdflib/plugins/parsers/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@


class JsonLDParser(Parser):
def __init__(self):
super(JsonLDParser, self).__init__()

def parse(self, source, sink, **kwargs):
# TODO: docstring w. args and return value
encoding = kwargs.get("encoding") or "utf-8"
Expand Down
6 changes: 0 additions & 6 deletions rdflib/plugins/parsers/notation3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1899,9 +1899,6 @@ class TurtleParser(Parser):
See http://www.w3.org/TR/turtle/
"""

def __init__(self):
pass

def parse(self, source, graph, encoding="utf-8", turtle=True):

if encoding not in [None, "utf-8"]:
Expand Down Expand Up @@ -1933,9 +1930,6 @@ class N3Parser(TurtleParser):

"""

def __init__(self):
pass

def parse(self, source, graph, encoding="utf-8"):
# we're currently being handed a Graph, not a ConjunctiveGraph
# context-aware is this implied by formula_aware
Expand Down
3 changes: 0 additions & 3 deletions rdflib/plugins/parsers/rdfxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,6 @@ def create_parser(target, store):


class RDFXMLParser(Parser):
def __init__(self):
pass

def parse(self, source, sink, **args):
self._parser = create_parser(source, sink)
content_handler = self._parser.getContentHandler()
Expand Down
3 changes: 0 additions & 3 deletions rdflib/plugins/parsers/trig.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ class TrigParser(Parser):

"""

def __init__(self):
pass

def parse(self, source, graph, encoding="utf-8"):

if encoding not in [None, "utf-8"]:
Expand Down
3 changes: 0 additions & 3 deletions rdflib/plugins/parsers/trix.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ def create_parser(store):
class TriXParser(Parser):
"""A parser for TriX. See http://sw.nokia.com/trix/"""

def __init__(self):
pass

def parse(self, source, sink, **args):
assert (
sink.store.context_aware
Expand Down