Updates the __str__ of BaseModel to handle Unicode characters

* Added a case of how to handle if the value is of type unicode
* Changed the logic for the log to use isinstance instead of string comparing the key

Change-Id: I97711e04d789ef6875e571925ddea74fc9ae6da4
This commit is contained in:
step6829
2013-11-22 12:24:34 -06:00
committed by step6829
parent 98f28333d1
commit b06056b2d5

View File

@@ -109,14 +109,18 @@ class BaseModel(object):
def __str__(self):
strng = '<{0} object> {1}'.format(
self.__class__.__name__, self.__REPR_SEPARATOR__)
for key in self.__dict__.keys():
if str(key) == '_log':
type(self).__name__, self.__REPR_SEPARATOR__)
for key in vars(self).keys():
val = getattr(self, key)
if isinstance(val, cclogging.logging.Logger):
continue
strng = '{0}{1} = {2}{3}'.format(
strng, str(key), str(self.__dict__[key]),
self.__REPR_SEPARATOR__)
return strng
elif isinstance(val, unicode):
strng = '{0}{1} = {2}{3}'.format(
strng, key, val.encode("utf-8"), self.__REPR_SEPARATOR__)
else:
strng = '{0}{1} = {2}{3}'.format(
strng, key, val, self.__REPR_SEPARATOR__)
return '{0}'.format(strng)
def __repr__(self):
return self.__str__()