Code Duplication    Length = 74-74 lines in 2 locations

gvm/protocols/gmpv7/gmpv7.py 2 locations

@@ 885-958 (lines=74) @@
882
883
        return self._send_xml_command(cmd)
884
885
    def create_note(
886
        self,
887
        text: str,
888
        nvt_oid: str,
889
        *,
890
        seconds_active: Optional[int] = None,
891
        hosts: Optional[List[str]] = None,
892
        port: Optional[int] = None,
893
        result_id: Optional[str] = None,
894
        severity: Optional[Severity] = None,
895
        task_id: Optional[str] = None,
896
        threat: Optional[SeverityLevel] = None
897
    ) -> Any:
898
        """Create a new note
899
900
        Arguments:
901
            text: Text of the new note
902
            nvt_id: OID of the nvt to which note applies
903
            seconds_active: Seconds note will be active. -1 on
904
                always, 0 off
905
            hosts: A list of hosts addresses
906
            port: Port to which the note applies
907
            result_id: UUID of a result to which note applies
908
            severity: Severity to which note applies
909
            task_id: UUID of task to which note applies
910
            threat: Severity level to which note applies. Will be converted to
911
                severity.
912
913
        Returns:
914
            The response. See :py:meth:`send_command` for details.
915
        """
916
        if not text:
917
            raise RequiredArgument(
918
                function=self.create_note.__name__, argument='text'
919
            )
920
921
        if not nvt_oid:
922
            raise RequiredArgument(
923
                function=self.create_note.__name__, argument='nvt_oid'
924
            )
925
926
        cmd = XmlCommand("create_note")
927
        cmd.add_element("text", text)
928
        cmd.add_element("nvt", attrs={"oid": nvt_oid})
929
930
        if seconds_active is not None:
931
            cmd.add_element("active", str(seconds_active))
932
933
        if hosts:
934
            cmd.add_element("hosts", _to_comma_list(hosts))
935
936
        if port:
937
            cmd.add_element("port", str(port))
938
939
        if result_id:
940
            cmd.add_element("result", attrs={"id": result_id})
941
942
        if severity:
943
            cmd.add_element("severity", str(severity))
944
945
        if task_id:
946
            cmd.add_element("task", attrs={"id": task_id})
947
948
        if threat is not None:
949
            if not isinstance(threat, SeverityLevel):
950
                raise InvalidArgumentType(
951
                    function="create_note",
952
                    argument="threat",
953
                    arg_type=SeverityLevel.__name__,
954
                )
955
956
            cmd.add_element("threat", threat.value)
957
958
        return self._send_xml_command(cmd)
959
960
    def clone_note(self, note_id: str) -> Any:
961
        """Clone an existing note
@@ 4974-5047 (lines=74) @@
4971
4972
        return self._send_xml_command(cmd)
4973
4974
    def modify_note(
4975
        self,
4976
        note_id: str,
4977
        text: str,
4978
        *,
4979
        seconds_active: Optional[int] = None,
4980
        hosts: Optional[List[str]] = None,
4981
        port: Optional[int] = None,
4982
        result_id: Optional[str] = None,
4983
        severity: Optional[Severity] = None,
4984
        task_id: Optional[str] = None,
4985
        threat: Optional[SeverityLevel] = None
4986
    ) -> Any:
4987
        """Modifies an existing note.
4988
4989
        Arguments:
4990
            note_id: UUID of note to modify.
4991
            text: The text of the note.
4992
            seconds_active: Seconds note will be active. -1 on always, 0 off.
4993
            hosts: A list of hosts addresses
4994
            port: Port to which note applies.
4995
            result_id: Result to which note applies.
4996
            severity: Severity to which note applies.
4997
            task_id: Task to which note applies.
4998
            threat: Threat level to which note applies. Will be converted to
4999
                severity.
5000
5001
        Returns:
5002
            The response. See :py:meth:`send_command` for details.
5003
        """
5004
        if not note_id:
5005
            raise RequiredArgument(
5006
                function=self.modify_note.__name__, argument='note_id'
5007
            )
5008
5009
        if not text:
5010
            raise RequiredArgument(
5011
                function=self.modify_note.__name__, argument='text'
5012
            )
5013
5014
        cmd = XmlCommand("modify_note")
5015
        cmd.set_attribute("note_id", note_id)
5016
        cmd.add_element("text", text)
5017
5018
        if seconds_active is not None:
5019
            cmd.add_element("active", str(seconds_active))
5020
5021
        if hosts:
5022
            cmd.add_element("hosts", _to_comma_list(hosts))
5023
5024
        if port:
5025
            cmd.add_element("port", str(port))
5026
5027
        if result_id:
5028
            cmd.add_element("result", attrs={"id": result_id})
5029
5030
        if severity:
5031
            cmd.add_element("severity", str(severity))
5032
5033
        if task_id:
5034
            cmd.add_element("task", attrs={"id": task_id})
5035
5036
        if threat is not None:
5037
5038
            if not isinstance(threat, SeverityLevel):
5039
                raise InvalidArgumentType(
5040
                    function=self.modify_note.__name__,
5041
                    argument='threat',
5042
                    arg_type=SeverityLevel.__name__,
5043
                )
5044
5045
            cmd.add_element("threat", threat.value)
5046
5047
        return self._send_xml_command(cmd)
5048
5049
    def modify_override(
5050
        self,