def str_repr(klass):
    """
    Implements string conversion methods for the given class.

    The given class must implement the __str__ method. This decorat
    will add __repr__ and __unicode__ (for Python 2).

    """
    if PY2:
        klass.__unicode__ = klass.__str__
        klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
    klass.__repr__ = lambda self: '<%s: %r>' % (self.__class__.__name__, str(self))
    return klass
Implements string conversion methods for the given class.

    The given class must implement the __str__ method. This decorat
    will add __repr__ and __unicode__ (for Python 2).