def undouble_unicode_escape(value):
    """Work around a unicode bug somewhere in the PloneLDAP stack
    that results in some values being doubly unicode encoded.
    """
    if isinstance(value, str):
        return value
    try:
        return value.encode('raw_unicode_escape').decode('utf-8')
    except UnicodeDecodeError:
        return value
    except Exception:
        return value
