(message_class, metadata)
Takes unserialized metadata and checks it looks sane

    This relies upon the required_metadata of each Message class
    to provide a list of metadata fields that are required.
Takes unserialized metadata and checks it looks sane
Takes unserialized metadata and checks it looks sane
def sanity_check_metadata(message_class, metadata):
    """Takes unserialized metadata and checks it looks sane

    This relies upon the required_metadata of each Message class
    to provide a list of metadata fields that are required.
    """
    for required_key in message_class.required_metadata:
        if required_key not in metadata:
            raise InvalidMessage(
                "Required key '{key}' missing in {cls} metadata. "
                "Found keys: {keys}".format(
                    key=required_key, keys=", ".join(metadata.keys()), cls=message_class.__name__
                )
            )
        elif not metadata.get(required_key):
            raise InvalidMessage(
                "Required key '{key}' present in {cls} metadata but value was empty"
                "".format(key=required_key, cls=message_class.__name__)
            )
def sanity_check_metadata ( message_class , metadata ) : for required_key in message_class . required_metadata : if required_key not in metadata : raise InvalidMessage ( "Required key '{key}' missing in {cls} metadata. " "Found keys: {keys}" . format ( key = required_key , keys = ", " . join ( metadata . keys ( ) ) , cls = message_class . __name__ ) ) elif not metadata . get ( required_key ) : raise InvalidMessage ( "Required key '{key}' present in {cls} metadata but value was empty" "" . format ( key = required_key , cls = message_class . __name__ ) )