def _insert_or_replace_entity(entity, require_encryption=False,<EOL>key_encryption_key=None, encryption_resolver=None):
_validate_entity(entity, key_encryption_key is not None)<EOL>_validate_encryption_required(require_encryption, key_encryption_key)<EOL>request = HTTPRequest()<EOL>request.method = '<STR_LIT>'<EOL>request.headers = {<EOL>_DEFAULT_CONTENT_TYPE_HEADER[<NUM_LIT:0>]: _DEFAULT_CONTENT_TYPE_HEADER[<NUM_LIT:1>],<EOL>_DEFAULT_ACCEPT_HEADER[<NUM_LIT:0>]: _DEFAULT_ACCEPT_HEADER[<NUM_LIT:1>],<EOL>}<EOL>if key_encryption_key:<EOL><INDENT>entity = _encrypt_entity(entity, key_encryption_key, encryption_resolver)<EOL><DEDENT>request.body = _get_request_body(_convert_entity_to_json(entity))<EOL>return request<EOL>
Constructs an insert or replace entity request.