Commits

Michał Górny committed d0c3996

Make StringCompat subclass unicode whenever necessary.

  • Participants
  • Parent commits 791c172

Comments (0)

Files changed (1)

File gentoopm/util.py

 	def __nonzero__(self):
 		return self.__bool__()
 
-class StringCompat(str):
-	"""
-	A helper class to create objects inheriting from string. It is basically
-	like subclassing str directly but with a nice C{repr()}.
-	"""
-
-	def __repr__(self):
-		return '%s(%s)' % (self.__class__.__name__, repr(str(self)))
+try:
+	class StringCompat(unicode):
+		"""
+		A helper class to create objects inheriting from string. It is basically
+		like subclassing str directly but with a nice C{repr()}.
+		"""
+
+		def __repr__(self):
+			return '%s(%s)' % (self.__class__.__name__, repr(unicode(self)))
+except NameError:
+	class StringCompat(str):
+		"""
+		A helper class to create objects inheriting from string. It is basically
+		like subclassing str directly but with a nice C{repr()}.
+		"""
+
+		def __repr__(self):
+			return '%s(%s)' % (self.__class__.__name__, repr(str(self)))
 
 class _SpaceSepIter(object):
 	def __getitem__(self, k):