|
24 | 24 |
|
25 | 25 | import threading |
26 | 26 | from urlparse import urlparse, urljoin, urldefrag |
27 | | -from string import ascii_letters, rsplit |
| 27 | +from string import ascii_letters |
28 | 28 | from random import choice |
29 | 29 | from itertools import islice |
30 | 30 | from datetime import date, time, datetime, timedelta |
|
35 | 35 | except ImportError: |
36 | 36 | from md5 import md5 |
37 | 37 |
|
| 38 | +import py3compat |
| 39 | + |
38 | 40 | class Node(object): |
39 | 41 | """ |
40 | 42 | A Node in the Graph. |
@@ -82,15 +84,15 @@ def n3(self): |
82 | 84 |
|
83 | 85 | def concrete(self): |
84 | 86 | if "#" in self: |
85 | | - return URIRef("/".join(rsplit(self, "#", 1))) |
| 87 | + return URIRef("/".join(self.rsplit("#", 1))) |
86 | 88 | else: |
87 | 89 | return self |
88 | 90 |
|
89 | 91 | def abstract(self): |
90 | 92 | if "#" not in self: |
91 | 93 | scheme, netloc, path, params, query, fragment = urlparse(self) |
92 | 94 | if path: |
93 | | - return URIRef("#".join(rsplit(self, "/", 1))) |
| 95 | + return URIRef("#".join(self.rsplit("/", 1))) |
94 | 96 | else: |
95 | 97 | if not self.endswith("#"): |
96 | 98 | return URIRef("%s#" % self) |
@@ -122,9 +124,13 @@ def __eq__(self, other): |
122 | 124 | return unicode(self)==unicode(other) |
123 | 125 | else: |
124 | 126 | return False |
| 127 | + |
| 128 | + def __hash__(self): |
| 129 | + return hash(URIRef) ^ hash(unicode(self)) |
125 | 130 |
|
126 | | - def __str__(self): |
127 | | - return self.encode() |
| 131 | + if not py3compat.PY3: |
| 132 | + def __str__(self): |
| 133 | + return self.encode() |
128 | 134 |
|
129 | 135 | def __repr__(self): |
130 | 136 | if self.__class__ is URIRef: |
@@ -226,9 +232,13 @@ def __eq__(self, other): |
226 | 232 | return unicode(self)==unicode(other) |
227 | 233 | else: |
228 | 234 | return False |
| 235 | + |
| 236 | + def __hash__(self): |
| 237 | + return hash(BNode) ^ hash(unicode(self)) |
229 | 238 |
|
230 | | - def __str__(self): |
231 | | - return self.encode() |
| 239 | + if not py3compat.PY3: |
| 240 | + def __str__(self): |
| 241 | + return self.encode() |
232 | 242 |
|
233 | 243 | def __repr__(self): |
234 | 244 | if self.__class__ is BNode: |
@@ -694,8 +704,9 @@ def _quote_encode(self): |
694 | 704 | return '"%s"' % self.replace('\n','\\n').replace('\\', '\\\\' |
695 | 705 | ).replace('"', '\\"') |
696 | 706 |
|
697 | | - def __str__(self): |
698 | | - return self.encode() |
| 707 | + if not py3compat.PY3: |
| 708 | + def __str__(self): |
| 709 | + return self.encode() |
699 | 710 |
|
700 | 711 | def __repr__(self): |
701 | 712 | args = [super(Literal, self).__repr__()] |
|
0 commit comments