Code Duplication    Length = 74-74 lines in 2 locations

gvm/protocols/gmpv7/__init__.py 2 locations

@@ 4893-4966 (lines=74) @@
4890
4891
        return self._send_xml_command(cmd)
4892
4893
    def modify_note(
4894
        self,
4895
        note_id: str,
4896
        text: str,
4897
        *,
4898
        seconds_active: Optional[int] = None,
4899
        hosts: Optional[List[str]] = None,
4900
        port: Optional[int] = None,
4901
        result_id: Optional[str] = None,
4902
        severity: Optional[Severity] = None,
4903
        task_id: Optional[str] = None,
4904
        threat: Optional[SeverityLevel] = None
4905
    ) -> Any:
4906
        """Modifies an existing note.
4907
4908
        Arguments:
4909
            note_id: UUID of note to modify.
4910
            text: The text of the note.
4911
            seconds_active: Seconds note will be active. -1 on always, 0 off.
4912
            hosts: A list of hosts addresses
4913
            port: Port to which note applies.
4914
            result_id: Result to which note applies.
4915
            severity: Severity to which note applies.
4916
            task_id: Task to which note applies.
4917
            threat: Threat level to which note applies. Will be converted to
4918
                severity.
4919
4920
        Returns:
4921
            The response. See :py:meth:`send_command` for details.
4922
        """
4923
        if not note_id:
4924
            raise RequiredArgument(
4925
                function=self.modify_note.__name__, argument='note_id'
4926
            )
4927
4928
        if not text:
4929
            raise RequiredArgument(
4930
                function=self.modify_note.__name__, argument='text'
4931
            )
4932
4933
        cmd = XmlCommand("modify_note")
4934
        cmd.set_attribute("note_id", note_id)
4935
        cmd.add_element("text", text)
4936
4937
        if not seconds_active is None:
4938
            cmd.add_element("active", str(seconds_active))
4939
4940
        if hosts:
4941
            cmd.add_element("hosts", _to_comma_list(hosts))
4942
4943
        if port:
4944
            cmd.add_element("port", str(port))
4945
4946
        if result_id:
4947
            cmd.add_element("result", attrs={"id": result_id})
4948
4949
        if severity:
4950
            cmd.add_element("severity", str(severity))
4951
4952
        if task_id:
4953
            cmd.add_element("task", attrs={"id": task_id})
4954
4955
        if threat is not None:
4956
4957
            if not isinstance(threat, SeverityLevel):
4958
                raise InvalidArgumentType(
4959
                    function=self.modify_note.__name__,
4960
                    argument='threat',
4961
                    arg_type=SeverityLevel.__name__,
4962
                )
4963
4964
            cmd.add_element("threat", threat.value)
4965
4966
        return self._send_xml_command(cmd)
4967
4968
    def modify_override(
4969
        self,
@@ 875-948 (lines=74) @@
872
873
        return self._send_xml_command(cmd)
874
875
    def create_note(
876
        self,
877
        text: str,
878
        nvt_oid: str,
879
        *,
880
        seconds_active: Optional[int] = None,
881
        hosts: Optional[List[str]] = None,
882
        port: Optional[int] = None,
883
        result_id: Optional[str] = None,
884
        severity: Optional[Severity] = None,
885
        task_id: Optional[str] = None,
886
        threat: Optional[SeverityLevel] = None
887
    ) -> Any:
888
        """Create a new note
889
890
        Arguments:
891
            text: Text of the new note
892
            nvt_id: OID of the nvt to which note applies
893
            seconds_active: Seconds note will be active. -1 on
894
                always, 0 off
895
            hosts: A list of hosts addresses
896
            port: Port to which the note applies
897
            result_id: UUID of a result to which note applies
898
            severity: Severity to which note applies
899
            task_id: UUID of task to which note applies
900
            threat: Severity level to which note applies. Will be converted to
901
                severity.
902
903
        Returns:
904
            The response. See :py:meth:`send_command` for details.
905
        """
906
        if not text:
907
            raise RequiredArgument(
908
                function=self.create_note.__name__, argument='text'
909
            )
910
911
        if not nvt_oid:
912
            raise RequiredArgument(
913
                function=self.create_note.__name__, argument='nvt_oid'
914
            )
915
916
        cmd = XmlCommand("create_note")
917
        cmd.add_element("text", text)
918
        cmd.add_element("nvt", attrs={"oid": nvt_oid})
919
920
        if not seconds_active is None:
921
            cmd.add_element("active", str(seconds_active))
922
923
        if hosts:
924
            cmd.add_element("hosts", _to_comma_list(hosts))
925
926
        if port:
927
            cmd.add_element("port", str(port))
928
929
        if result_id:
930
            cmd.add_element("result", attrs={"id": result_id})
931
932
        if severity:
933
            cmd.add_element("severity", str(severity))
934
935
        if task_id:
936
            cmd.add_element("task", attrs={"id": task_id})
937
938
        if threat is not None:
939
            if not isinstance(threat, SeverityLevel):
940
                raise InvalidArgumentType(
941
                    function="create_note",
942
                    argument="threat",
943
                    arg_type=SeverityLevel.__name__,
944
                )
945
946
            cmd.add_element("threat", threat.value)
947
948
        return self._send_xml_command(cmd)
949
950
    def clone_note(self, note_id: str) -> Any:
951
        """Clone an existing note