Skip to content

Commit c1bfa2b

Browse files
committed
Changes so rdflib can be imported after installation in Python 3.
1 parent e38b013 commit c1bfa2b

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

rdflib/store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def triples_choices(self, (subject, predicate, object_),context=None):
233233
for (s1, p1, o1), cg in self.triples((subject,None,object_),context):
234234
yield (s1, p1, o1), cg
235235

236-
def triples(self, (subject, predicate, object), context=None):
236+
def triples(self, triple_pattern, context=None):
237237
"""
238238
A generator over all the triples matching the pattern. Pattern can
239239
include any objects for used for comparing against nodes in the store, for
@@ -242,6 +242,7 @@ def triples(self, (subject, predicate, object), context=None):
242242
A conjunctive query can be indicated by either providing a value of None
243243
for the context or the identifier associated with the Conjunctive Graph (if it's context aware).
244244
"""
245+
subject, predicate, object = triple_pattern
245246

246247
# variants of triples will be done if / when optimization is needed
247248

rdflib/term.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import threading
2626
from urlparse import urlparse, urljoin, urldefrag
27-
from string import ascii_letters, rsplit
27+
from string import ascii_letters
2828
from random import choice
2929
from itertools import islice
3030
from datetime import date, time, datetime, timedelta
@@ -35,6 +35,8 @@
3535
except ImportError:
3636
from md5 import md5
3737

38+
import py3compat
39+
3840
class Node(object):
3941
"""
4042
A Node in the Graph.
@@ -82,15 +84,15 @@ def n3(self):
8284

8385
def concrete(self):
8486
if "#" in self:
85-
return URIRef("/".join(rsplit(self, "#", 1)))
87+
return URIRef("/".join(self.rsplit("#", 1)))
8688
else:
8789
return self
8890

8991
def abstract(self):
9092
if "#" not in self:
9193
scheme, netloc, path, params, query, fragment = urlparse(self)
9294
if path:
93-
return URIRef("#".join(rsplit(self, "/", 1)))
95+
return URIRef("#".join(self.rsplit("/", 1)))
9496
else:
9597
if not self.endswith("#"):
9698
return URIRef("%s#" % self)
@@ -122,9 +124,13 @@ def __eq__(self, other):
122124
return unicode(self)==unicode(other)
123125
else:
124126
return False
127+
128+
def __hash__(self):
129+
return hash(URIRef) ^ hash(unicode(self))
125130

126-
def __str__(self):
127-
return self.encode()
131+
if not py3compat.PY3:
132+
def __str__(self):
133+
return self.encode()
128134

129135
def __repr__(self):
130136
if self.__class__ is URIRef:
@@ -226,9 +232,13 @@ def __eq__(self, other):
226232
return unicode(self)==unicode(other)
227233
else:
228234
return False
235+
236+
def __hash__(self):
237+
return hash(BNode) ^ hash(unicode(self))
229238

230-
def __str__(self):
231-
return self.encode()
239+
if not py3compat.PY3:
240+
def __str__(self):
241+
return self.encode()
232242

233243
def __repr__(self):
234244
if self.__class__ is BNode:
@@ -694,8 +704,9 @@ def _quote_encode(self):
694704
return '"%s"' % self.replace('\n','\\n').replace('\\', '\\\\'
695705
).replace('"', '\\"')
696706

697-
def __str__(self):
698-
return self.encode()
707+
if not py3compat.PY3:
708+
def __str__(self):
709+
return self.encode()
699710

700711
def __repr__(self):
701712
args = [super(Literal, self).__repr__()]

rdflib/util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"""
3131

3232
from calendar import timegm
33-
from string import rsplit
3433
from time import altzone
3534
#from time import daylight
3635
from time import gmtime
@@ -119,11 +118,11 @@ def from_n3(s, default=None, backend=None):
119118
return URIRef(s[1:-1])
120119
elif s.startswith('"'):
121120
# TODO: would a regex be faster?
122-
value, rest = rsplit(s, '"', 1)
121+
value, rest = s.rsplit('"', 1)
123122
value = value[1:] # strip leading quote
124123
if rest.startswith("@"):
125124
if "^^" in rest:
126-
language, rest = rsplit(rest, '^^', 1)
125+
language, rest = rest.rsplit('^^', 1)
127126
language = language[1:] # strip leading at sign
128127
else:
129128
language = rest[1:] # strip leading at sign

0 commit comments

Comments
 (0)