From: W. Trevor King Date: Sat, 26 Jun 2010 21:11:50 +0000 (-0400) Subject: Added string output methods to AttributeHolder. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b30cf3cd2a83c189b8a7bd8ee4938387d64df40a;p=sitecorepy.git Added string output methods to AttributeHolder. --- diff --git a/sitecore/prof/__init__.py b/sitecore/prof/__init__.py index 32bd679..d8c6662 100644 --- a/sitecore/prof/__init__.py +++ b/sitecore/prof/__init__.py @@ -67,6 +67,26 @@ class AttributeHolder (object): assert field in self.fields, '%s not in %s' % (field, self.fields) setattr(self, field, value) + def __str__(self): + return self.__unicode__() + + def __repr__(self): + return self.__unicode__() + + def __unicode__(self): + lines = ['%s:' % self.__class__.__name__] + for field in self.fields: + value = getattr(self, field) + if value == None: + continue + value_lines = unicode(value).splitlines() + if isinstance(value, AttributeHolder): + prefix = ' ' + else: + prefix = ' %s: ' % field + lines.extend(['%s%s' % (prefix, L) for L in value_lines]) + return u'\n'.join(lines) + class Name (AttributeHolder): fields = ['first_middle', 'last']