Code Duplication    Length = 44-48 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 2183-2230 (lines=48) @@
2180
2181
        return self._send_xml_command(cmd)
2182
2183
    def modify_filter(
2184
        self,
2185
        filter_id: str,
2186
        *,
2187
        comment: Optional[str] = None,
2188
        name: Optional[str] = None,
2189
        term: Optional[str] = None,
2190
        filter_type: Optional[FilterType] = None,
2191
    ) -> Any:
2192
        """Modifies an existing filter.
2193
2194
        Arguments:
2195
            filter_id: UUID of the filter to be modified
2196
            comment: Comment on filter.
2197
            name: Name of filter.
2198
            term: Filter term.
2199
            filter_type: Resource type filter applies to.
2200
2201
        Returns:
2202
            The response. See :py:meth:`send_command` for details.
2203
        """
2204
        if not filter_id:
2205
            raise RequiredArgument(
2206
                function=self.modify_filter.__name__, argument='filter_id'
2207
            )
2208
2209
        cmd = XmlCommand("modify_filter")
2210
        cmd.set_attribute("filter_id", filter_id)
2211
2212
        if comment:
2213
            cmd.add_element("comment", comment)
2214
2215
        if name:
2216
            cmd.add_element("name", name)
2217
2218
        if term:
2219
            cmd.add_element("term", term)
2220
2221
        if filter_type:
2222
            if not isinstance(filter_type, self.types.FilterType):
2223
                raise InvalidArgumentType(
2224
                    function=self.modify_filter.__name__,
2225
                    argument='filter_type',
2226
                    arg_type=FilterType.__name__,
2227
                )
2228
            cmd.add_element("type", filter_type.value)
2229
2230
        return self._send_xml_command(cmd)
2231
2232
    def create_schedule(
2233
        self,
@@ 2138-2181 (lines=44) @@
2135
2136
        return self._send_xml_command(cmd)
2137
2138
    def create_filter(
2139
        self,
2140
        name: str,
2141
        *,
2142
        filter_type: Optional[FilterType] = None,
2143
        comment: Optional[str] = None,
2144
        term: Optional[str] = None,
2145
    ) -> Any:
2146
        """Create a new filter
2147
2148
        Arguments:
2149
            name: Name of the new filter
2150
            filter_type: Filter for entity type
2151
            comment: Comment for the filter
2152
            term: Filter term e.g. 'name=foo'
2153
2154
        Returns:
2155
            The response. See :py:meth:`send_command` for details.
2156
        """
2157
        if not name:
2158
            raise RequiredArgument(
2159
                function=self.create_filter.__name__, argument="name"
2160
            )
2161
2162
        cmd = XmlCommand("create_filter")
2163
        _xmlname = cmd.add_element("name", name)
2164
2165
        if comment:
2166
            cmd.add_element("comment", comment)
2167
2168
        if term:
2169
            cmd.add_element("term", term)
2170
2171
        if filter_type:
2172
            if not isinstance(filter_type, self.types.FilterType):
2173
                raise InvalidArgumentType(
2174
                    function=self.create_filter.__name__,
2175
                    argument="filter_type",
2176
                    arg_type=self.types.FilterType.__name__,
2177
                )
2178
2179
            cmd.add_element("type", filter_type.value)
2180
2181
        return self._send_xml_command(cmd)
2182
2183
    def modify_filter(
2184
        self,