diff options
Diffstat (limited to 'rdflib/paths.py')
-rw-r--r-- | rdflib/paths.py | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/rdflib/paths.py b/rdflib/paths.py index 3c8da985..31e2230f 100644 --- a/rdflib/paths.py +++ b/rdflib/paths.py @@ -184,7 +184,6 @@ No vars specified: """) -from functools import total_ordering from rdflib.term import URIRef, Node @@ -194,17 +193,38 @@ ZeroOrMore = '*' OneOrMore = '+' ZeroOrOne = '?' -@total_ordering + class Path(object): def eval(self, graph, subj=None, obj=None): raise NotImplementedError() + def __hash__(self): + return hash(repr(self)) + + def __eq__(self, other): + return repr(self) == repr(other) + def __lt__(self, other): if not isinstance(other, (Path, Node)): raise TypeError('unorderable types: %s() < %s()' % ( repr(self), repr(other))) return repr(self) < repr(other) + def __le__(self, other): + if not isinstance(other, (Path, Node)): + raise TypeError('unorderable types: %s() < %s()' % ( + repr(self), repr(other))) + return repr(self) <= repr(other) + + def __ne__(self, other): + return not self == other + + def __gt__(self, other): + return not self <= other + + def __ge__(self, other): + return not self < other + class InvPath(Path): @@ -219,7 +239,7 @@ class InvPath(Path): return "Path(~%s)" % (self.arg,) def n3(self): - return '^%s'%self.arg.n3() + return '^%s' % self.arg.n3() class SequencePath(Path): @@ -387,7 +407,7 @@ class MulPath(Path): return "Path(%s%s)" % (self.path, self.mod) def n3(self): - return '%s%s'%(self.path, self.mod) + return '%s%s' % (self.path, self.mod) @@ -420,7 +440,7 @@ class NegatedPath(Path): return "Path(! %s)" % ",".join(str(x) for x in self.args) def n3(self): - return '!(%s)'%('|'.join(self.args)) + return '!(%s)' % ('|'.join(self.args)) class PathList(list): |