@utilities.arguments_not_none<EOL><INDENT>def update_answer(self, answer_form):<DEDENT>
<EOL>from dlkit.abstract_osid.assessment.objects import AnswerForm as ABCAnswerForm<EOL>collection = JSONClientValidated('<STR_LIT>',<EOL>collection='<STR_LIT>',<EOL>runtime=self._runtime)<EOL>if not isinstance(answer_form, ABCAnswerForm):<EOL><INDENT>raise errors.InvalidArgument('<STR_LIT>')<EOL><DEDENT>if not answer_form.is_for_update():<EOL><INDENT>raise errors.InvalidArgument('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>if self._forms[answer_form.get_id().get_identifier()] == UPDATED:<EOL><INDENT>raise errors.IllegalState('<STR_LIT>')<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>raise errors.Unsupported('<STR_LIT>')<EOL><DEDENT>if not answer_form.is_valid():<EOL><INDENT>raise errors.InvalidArgument('<STR_LIT>')<EOL><DEDENT>item_id = Id(answer_form._my_map['<STR_LIT>']).get_identifier()<EOL>item = collection.find_one(<EOL>{'<STR_LIT>': [{'<STR_LIT>': ObjectId(item_id)},<EOL>{'<STR_LIT>' + self._catalog_name + '<STR_LIT>': {'<STR_LIT>': [str(self._catalog_id)]}}]})<EOL>index = <NUM_LIT:0><EOL>found = False<EOL>for i in item['<STR_LIT>']:<EOL><INDENT>if i['<STR_LIT>'] == ObjectId(answer_form._my_map['<STR_LIT>']):<EOL><INDENT>item['<STR_LIT>'].pop(index)<EOL>item['<STR_LIT>'].insert(index, answer_form._my_map)<EOL>found = True<EOL>break<EOL><DEDENT>index += <NUM_LIT:1><EOL><DEDENT>if not found:<EOL><INDENT>raise errors.NotFound()<EOL><DEDENT>try:<EOL><INDENT>collection.save(item)<EOL><DEDENT>except:  <EOL><INDENT>raise errors.OperationFailed()<EOL><DEDENT>self._forms[answer_form.get_id().get_identifier()] = UPDATED<EOL>from .objects import Answer<EOL>return Answer(<EOL>osid_object_map=answer_form._my_map,<EOL>runtime=self._runtime,<EOL>proxy=self._proxy)<EOL>
Updates an existing answer.

        arg:    answer_form (osid.assessment.AnswerForm): the form
                containing the elements to be updated
        raise:  IllegalState - ``answer_form`` already used in an update
                transaction
        raise:  InvalidArgument - the form contains an invalid value
        raise:  NullArgument - ``answer_form`` is ``null``
        raise:  OperationFailed - unable to complete request
        raise:  PermissionDenied - authorization failure occurred
        raise:  Unsupported - ``answer_form`` did not originate from
                ``get_answer_form_for_update()``
        *compliance: mandatory -- This method must be implemented.*