Skip to content

Commit

Permalink
properly cast Namespace to str, unicode and bytes on py2 and py3
Browse files Browse the repository at this point in the history
  • Loading branch information
joernhees authored and gromgull committed Oct 27, 2018
1 parent 3af5267 commit 9fd7d94
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rdflib/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,17 @@ def __add__(self, other):
"""Syntactic sugar to allow to write ns[foo] as ns + foo."""
return self[other]

def __str__(self):
def __unicode__(self):
return self.__prefix__

def __bytes__(self):
return self.__prefix__.encode('utf-8')

if PY3:
__str__ = __unicode__
else:
__str__ = __bytes__

def __repr__(self):
t = type(self)
return "%s(%r)" % (t.__module__ + '.' + t.__name__, self.__prefix__)
Expand Down

0 comments on commit 9fd7d94

Please sign in to comment.