def safe_decode(s):
    """Safely decodes a binary string to unicode"""
    if isinstance(s, unicode):
        return s
    elif isinstance(s, bytes):
        return s.decode(defenc, errors='replace')
    raise TypeError('Expected bytes or text, but got %r' % (s,))
dataset/ETHPy150Open gitpython-developers/GitPython/git/compat.py/safe_decode/original