def escape_bytes(bytes_value):
    """Convert a byte sequence to a properly escaped for LDAP (format BACKSLASH HEX HEX) string."""
    if bytes_value:
        if isinstance(bytes_value, str):
            bytes_value = bytearray(bytes_value, encoding="utf-8")
        escaped = "\\".join([("%02x" % int(b)) for b in bytes_value])
    else:
        escaped = ""
    result = ("\\" + escaped) if escaped else ""
    return result