コード例 #1
0
 def __str__(self):
     """Show the class name and an identifying attribute."""
     if hasattr(self, 'name') and self.name:
         return _sugar.trim_str(self.name, maxlen=40)
     if hasattr(self, 'value') and self.value:
         return _sugar.trim_str(unicode(self.value), maxlen=40)
     if hasattr(self, 'id') and self.id:
         return str(self.id)
     return self.__class__.__name__
コード例 #2
0
 def __repr__(self):
     """Show this object's constructor with its primitive arguments."""
     s = '%s(%s)' % (self.__class__.__name__,
                     ', '.join("%s='%s'"
                               % (key, _sugar.trim_str(unicode(val)))
                         for key, val in self.__dict__.iteritems()
                         if val is not None
                         and type(val) in (str, int, float, bool, unicode)))
     return s.encode('utf-8')