diff options
-rw-r--r-- | rdflib/plugins/sparql/sparql.py | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/rdflib/plugins/sparql/sparql.py b/rdflib/plugins/sparql/sparql.py index f24aa564..5df3db68 100644 --- a/rdflib/plugins/sparql/sparql.py +++ b/rdflib/plugins/sparql/sparql.py @@ -164,7 +164,7 @@ class FrozenBindings(FrozenDict): if not isinstance(key, Node): key = Variable(key) - if not type(key) in (BNode, Variable): + if not isinstance(key, (BNode, Variable)): return key if key not in self._d: @@ -177,22 +177,20 @@ class FrozenBindings(FrozenDict): def merge(self, other): res = FrozenBindings(self.ctx, itertools.chain(self.items(), other.items())) - return res - def _now(self): + @property + def now(self): return self.ctx.now - def _bnodes(self): + @property + def bnodes(self): return self.ctx.bnodes - def _prologue(self): + @property + def prologue(self): return self.ctx.prologue - prologue = property(_prologue) - bnodes = property(_bnodes) - now = property(_now) - def forget(self, before, _except=None): """ return a frozen dict only of bindings made in self @@ -222,8 +220,7 @@ class FrozenBindings(FrozenDict): return FrozenBindings(self.ctx, (x for x in self.items() if x[0] in these)) -class QueryContext(object): - +class QueryContext: """ Query context - passed along when evaluating the query """ @@ -260,7 +257,9 @@ class QueryContext(object): r.bnodes = self.bnodes return r - def _get_dataset(self): + @property + def dataset(self): + """"current dataset""" if self._dataset is None: raise Exception( "You performed a query operation requiring " @@ -269,8 +268,6 @@ class QueryContext(object): ) return self._dataset - dataset = property(_get_dataset, doc="current dataset") - def load(self, source, default=False, **kwargs): def _load(graph, source): try: @@ -306,7 +303,7 @@ class QueryContext(object): def __getitem__(self, key): # in SPARQL BNodes are just labels - if not type(key) in (BNode, Variable): + if not isinstance(key, (BNode, Variable)): return key try: return self.bindings[key] @@ -348,11 +345,6 @@ class QueryContext(object): def clean(self): return self.clone([]) - # def pop(self): - # self.bindings = self.bindings.outer - # if self.bindings is None: - # raise Exception("We've bottomed out of the bindings stack!") - def thaw(self, frozenbindings): """ Create a new read/write query context from the given solution @@ -362,8 +354,7 @@ class QueryContext(object): return c -class Prologue(object): - +class Prologue: """ A class for holding prefixing bindings and base URI information """ @@ -402,7 +393,7 @@ class Prologue(object): return iri -class Query(object): +class Query: """ A parsed and translated query """ |