def _as_str(value):
    """Helper function to convert bytes back to str. This is used in
    the __str__ functions for simple string types. If you want a custom
    encoding, use an explicit decode call on the value.
    """
    if isinstance(value, bytes):
        return value.decode('utf-8', 'replace')
    elif isinstance(value, str):
        return value
    else:
        raise TypeError('expected bytes')
