diff options
author | Joern Hees <dev@joernhees.de> | 2015-11-29 20:16:31 +0100 |
---|---|---|
committer | Joern Hees <dev@joernhees.de> | 2015-11-29 20:59:30 +0100 |
commit | 25bfa5bd1f200dae993cddf21cc8726d6db00c63 (patch) | |
tree | a781bd16c40d974c9e5075d79dfa35bd0a4e6854 | |
parent | 57e8f7173d95047d4fa71dc4c684aaa0fd6c15a9 (diff) | |
download | rdflib-fix-issue-545.tar.gz |
expanded path comparison ops in order to keep py2.6 support and not use total_orderingfix-issue-545
-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): |