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:
@@ -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__()
|
||||
|
||||
Reference in New Issue
Block a user