'Bulk verfies signatures of json objects, bulk fetching keys as
necessary.
Args:
server_and_json (list): List of pairs of (server_name, json_object)
Returns:
list of deferreds indicating success or failure to verify each
json object\'s signature for the given server_name.'

def verify_json_objects_for_server(self, server_and_json):

    verify_requests = []
    for (server_name, json_object) in server_and_json:
        key_ids = signature_ids(json_object, server_name)
        if (not key_ids):
            logger.warn('Request    from    %s:    no    supported    signature    keys', server_name)
            deferred = defer.fail(SynapseError(400, 'Not    signed    with    a    supported    algorithm', Codes.UNAUTHORIZED))
        else:
            deferred = defer.Deferred()
        logger.debug('Verifying    for    %s    with    key_ids    %s', server_name, key_ids)
        verify_request = VerifyKeyRequest(server_name, key_ids, json_object, deferred)
        verify_requests.append(verify_request)
    @defer.inlineCallbacks
    def handle_key_deferred(verify_request):
        server_name = verify_request.server_name
        try:
            (_, key_id, verify_key) = (yield verify_request.deferred)
        except IOError as e:
            logger.warn('Got    IOError    when    downloading    keys    for    %s:    %s    %s', server_name, type(e).__name__, str(e.message))
            raise SynapseError(502, ('Error    downloading    keys    for    %s' % (server_name,)), Codes.UNAUTHORIZED)
        except Exception as e:
            logger.exception('Got    Exception    when    downloading    keys    for    %s:    %s    %s', server_name, type(e).__name__, str(e.message))
            raise SynapseError(401, ('No    key    for    %s    with    id    %s' % (server_name, key_ids)), Codes.UNAUTHORIZED)
        json_object = verify_request.json_object
        logger.debug(('Got    key    %s    %s:%s    for    server    %s,    verifying' % (key_id, verify_key.alg, verify_key.version, server_name)))
        try:
            verify_signed_json(json_object, server_name, verify_key)
        except:
            raise SynapseError(401, ('Invalid    signature    for    server    %s    with    key    %s:%s' % (server_name, verify_key.alg, verify_key.version)), Codes.UNAUTHORIZED)
    server_to_deferred = {server_name: defer.Deferred() for (server_name, _) in server_and_json}
    with PreserveLoggingContext():
        wait_on_deferred = self.wait_for_previous_lookups([server_name for (server_name, _) in server_and_json], server_to_deferred)
        wait_on_deferred.addBoth((lambda _: self.get_server_verify_keys(verify_requests)))
        server_to_request_ids = {}
        def remove_deferreds(res, server_name, verify_request):
            request_id = id(verify_request)
            server_to_request_ids[server_name].discard(request_id)
            if (not server_to_request_ids[server_name]):
                d = server_to_deferred.pop(server_name, None)
                if d:
                    d.callback(None)
            return res
        for verify_request in verify_requests:
            server_name = verify_request.server_name
            request_id = id(verify_request)
            server_to_request_ids.setdefault(server_name, set()).add(request_id)
            deferred.addBoth(remove_deferreds, server_name, verify_request)
    return [preserve_context_over_fn(handle_key_deferred, verify_request) for verify_request in verify_requests]
