def tostring(barray):
    """Convert a byte array to string in utf-8 noop if already a string."""
    if isinstance(barray, str):
        return barray
    if isinstance(barray, bytes):
        # return str(barray, 'utf-8', errors='replace')  # Python 3
        return barray.decode(encoding="utf=8", errors="replace")