Code Duplication    Length = 44-48 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 3004-3051 (lines=48) @@
3001
3002
        return self._send_xml_command(cmd)
3003
3004
    def modify_filter(
3005
        self,
3006
        filter_id: str,
3007
        *,
3008
        comment: Optional[str] = None,
3009
        name: Optional[str] = None,
3010
        term: Optional[str] = None,
3011
        filter_type: Optional[FilterType] = None,
3012
    ) -> Any:
3013
        """Modifies an existing filter.
3014
3015
        Arguments:
3016
            filter_id: UUID of the filter to be modified
3017
            comment: Comment on filter.
3018
            name: Name of filter.
3019
            term: Filter term.
3020
            filter_type: Resource type filter applies to.
3021
3022
        Returns:
3023
            The response. See :py:meth:`send_command` for details.
3024
        """
3025
        if not filter_id:
3026
            raise RequiredArgument(
3027
                function=self.modify_filter.__name__, argument='filter_id'
3028
            )
3029
3030
        cmd = XmlCommand("modify_filter")
3031
        cmd.set_attribute("filter_id", filter_id)
3032
3033
        if comment:
3034
            cmd.add_element("comment", comment)
3035
3036
        if name:
3037
            cmd.add_element("name", name)
3038
3039
        if term:
3040
            cmd.add_element("term", term)
3041
3042
        if filter_type:
3043
            if not isinstance(filter_type, self.types.FilterType):
3044
                raise InvalidArgumentType(
3045
                    function=self.modify_filter.__name__,
3046
                    argument='filter_type',
3047
                    arg_type=FilterType.__name__,
3048
                )
3049
            cmd.add_element("type", filter_type.value)
3050
3051
        return self._send_xml_command(cmd)
3052
3053
    def create_schedule(
3054
        self,
@@ 2959-3002 (lines=44) @@
2956
2957
        return self._send_xml_command(cmd)
2958
2959
    def create_filter(
2960
        self,
2961
        name: str,
2962
        *,
2963
        filter_type: Optional[FilterType] = None,
2964
        comment: Optional[str] = None,
2965
        term: Optional[str] = None,
2966
    ) -> Any:
2967
        """Create a new filter
2968
2969
        Arguments:
2970
            name: Name of the new filter
2971
            filter_type: Filter for entity type
2972
            comment: Comment for the filter
2973
            term: Filter term e.g. 'name=foo'
2974
2975
        Returns:
2976
            The response. See :py:meth:`send_command` for details.
2977
        """
2978
        if not name:
2979
            raise RequiredArgument(
2980
                function=self.create_filter.__name__, argument="name"
2981
            )
2982
2983
        cmd = XmlCommand("create_filter")
2984
        _xmlname = cmd.add_element("name", name)
2985
2986
        if comment:
2987
            cmd.add_element("comment", comment)
2988
2989
        if term:
2990
            cmd.add_element("term", term)
2991
2992
        if filter_type:
2993
            if not isinstance(filter_type, self.types.FilterType):
2994
                raise InvalidArgumentType(
2995
                    function=self.create_filter.__name__,
2996
                    argument="filter_type",
2997
                    arg_type=self.types.FilterType.__name__,
2998
                )
2999
3000
            cmd.add_element("type", filter_type.value)
3001
3002
        return self._send_xml_command(cmd)
3003
3004
    def modify_filter(
3005
        self,