From b30cf3cd2a83c189b8a7bd8ee4938387d64df40a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 26 Jun 2010 17:11:50 -0400 Subject: [PATCH] Added string output methods to AttributeHolder. --- sitecore/prof/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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'] -- 2.26.2