six: use PY2, PY3 from six, __nonzero__/__bool__ compatibility
@@ -56,6 +56,8 @@ from isodate import parse_time, parse_date, parse_datetime
import rdflib
from . import py3compat
+from .py3compat import PY2
+from .py3compat import PY3
from .py3compat import b
from .py3compat import urldefrag
from .py3compat import urljoin
@@ -261,7 +263,7 @@ class URIRef(Identifier):
def __getnewargs__(self):
return (unicode(self), )
- if not py3compat.PY3:
+ if PY2:
def __str__(self):
return self.encode()
@@ -404,7 +406,7 @@ class BNode(Identifier):
def __reduce__(self):
return (BNode, (unicode(self),))
- if not py3compat.PY3:
+ if PY2:
def __str__(self):
return self.encode()
@@ -645,7 +647,7 @@ class Literal(Identifier):
s = unicode.__add__(self, val)
return Literal(s, self.language, self.datatype)
- def __nonzero__(self):
+ def __bool__(self):
"""
Is the Literal "True"
This is used for if statements, bool(literal), etc.
@@ -654,6 +656,9 @@ class Literal(Identifier):
return bool(self.value)
return len(self) != 0
+ if PY2:
+ __nonzero__ = __bool__
+
@py3compat.format_doctest_out
def __neg__(self):
"""
@@ -1265,7 +1270,7 @@ class Literal(Identifier):
'"', '\\"').replace(
'\r', '\\r')
- if not py3compat.PY3:
+ if PY2:
def __str__(self):
return self.encode()
@@ -1292,7 +1297,7 @@ class Literal(Identifier):
def _parseXML(xmlstring):
- if not py3compat.PY3:
+ if PY2:
xmlstring = xmlstring.encode('utf-8')
retval = xml.dom.minidom.parseString(
"<rdflibtoplevelelement>%s</rdflibtoplevelelement>" % xmlstring)
