def handle_send(<EOL>entity: BaseEntity,<EOL>author_user: UserType,<EOL>recipients: List[Dict],<EOL>parent_user: UserType = None,<EOL>) -> None:
payloads = []<EOL>public_payloads = {<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": set(),<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": set(),<EOL>},<EOL>}<EOL>unique_recipients = unique_everseen(recipients)<EOL>for recipient in unique_recipients:<EOL><INDENT>fid = recipient["<STR_LIT>"]<EOL>public_key = recipient.get("<STR_LIT>")<EOL>protocol = recipient["<STR_LIT>"]<EOL>public = recipient["<STR_LIT>"]<EOL>if protocol == "<STR_LIT>":<EOL><INDENT>try:<EOL><INDENT>payload = handle_create_payload(entity, author_user, protocol, parent_user=parent_user)<EOL>if public:<EOL><INDENT>payload["<STR_LIT:to>"] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>payload["<STR_LIT:to>"] = fid<EOL><DEDENT>payload = json.dumps(payload).encode("<STR_LIT:utf-8>")<EOL><DEDENT>except Exception as ex:<EOL><INDENT>logger.error("<STR_LIT>", fid, ex)<EOL>continue<EOL><DEDENT>payloads.append({<EOL>"<STR_LIT>": get_http_authentication(author_user.private_key, f"<STR_LIT>"),<EOL>"<STR_LIT>": payload,<EOL>"<STR_LIT>": '<STR_LIT>',<EOL>"<STR_LIT>": {fid},<EOL>})<EOL><DEDENT>elif protocol == "<STR_LIT>":<EOL><INDENT>if public:<EOL><INDENT>if public_key:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not public_payloads[protocol]["<STR_LIT>"]:<EOL><INDENT>public_payloads[protocol]["<STR_LIT>"] = handle_create_payload(<EOL>entity, author_user, protocol, parent_user=parent_user,<EOL>)<EOL><DEDENT>public_payloads["<STR_LIT>"]["<STR_LIT>"].add(fid)<EOL><DEDENT>else:<EOL><INDENT>if not public_key:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>try:<EOL><INDENT>payload = handle_create_payload(<EOL>entity, author_user, "<STR_LIT>", to_user_key=public_key, parent_user=parent_user,<EOL>)<EOL>payload = json.dumps(payload)<EOL><DEDENT>except Exception as ex:<EOL><INDENT>logger.error("<STR_LIT>", fid, ex)<EOL>continue<EOL><DEDENT>payloads.append({<EOL>"<STR_LIT>": {fid}, "<STR_LIT>": payload, "<STR_LIT>": "<STR_LIT:application/json>", "<STR_LIT>": None,<EOL>})<EOL><DEDENT><DEDENT><DEDENT>if public_payloads["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>payloads.append({<EOL>"<STR_LIT>": public_payloads["<STR_LIT>"]["<STR_LIT>"], "<STR_LIT>": public_payloads["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": "<STR_LIT>", "<STR_LIT>": None,<EOL>})<EOL><DEDENT>logger.debug("<STR_LIT>", payloads)<EOL>for payload in payloads:<EOL><INDENT>for url in payload["<STR_LIT>"]:<EOL><INDENT>try:<EOL><INDENT>send_document(<EOL>url,<EOL>payload["<STR_LIT>"],<EOL>auth=payload["<STR_LIT>"],<EOL>headers={"<STR_LIT:Content-Type>": payload["<STR_LIT>"]},<EOL>)<EOL><DEDENT>except Exception as ex:<EOL><INDENT>logger.error("<STR_LIT>", url, ex, payload["<STR_LIT>"])<EOL><DEDENT><DEDENT><DEDENT>
Send an entity to remote servers.

    Using this we will build a list of payloads per protocol. After that, each recipient will get the generated
    protocol payload delivered. Delivery to the same endpoint will only be done once so it's ok to include
    the same endpoint as a receiver multiple times.

    Any given user arguments must have ``private_key`` and ``fid`` attributes.

    :arg entity: Entity object to send. Can be a base entity or a protocol specific one.
    :arg author_user: User authoring the object.
    :arg recipients: A list of recipients to delivery to. Each recipient is a dict
                     containing at minimum the "fid", "public" and "protocol" keys.

                     For ActivityPub and Diaspora payloads, "fid" should be an URL of the endpoint to deliver to.

                     The "protocol" should be a protocol name that is known for this recipient.

                     The "public" value should be a boolean to indicate whether the payload should be flagged as a
                     public payload.

                     TODO: support guessing the protocol over networks? Would need caching of results

                     For private deliveries to Diaspora protocol recipients, "public_key" is also required.

                     For example
                     [
                        {
                            "fid": "https://domain.tld/receive/users/1234-5678-0123-4567",
                            "protocol": "diaspora",
                            "public": False,
                            "public_key": <RSAPublicKey object>,
                        },
                        {
                            "fid": "https://domain2.tld/receive/public",
                            "protocol": "diaspora",
                            "public": True,
                        },
                        {
                            "fid": "https://domain4.tld/sharedinbox/",
                            "protocol": "activitypub",
                            "public": True,
                        },
                        {
                            "fid": "https://domain4.tld/profiles/jill",
                            "protocol": "activitypub",
                            "public": False,
                        },
                     ]
    :arg parent_user: (Optional) User object of the parent object, if there is one. This must be given for the
                      Diaspora protocol if a parent object exists, so that a proper ``parent_author_signature`` can
                      be generated. If given, the payload will be sent as this user.