Code Duplication    Length = 44-48 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 2364-2411 (lines=48) @@
2361
2362
        return self._send_xml_command(cmd)
2363
2364
    def modify_filter(
2365
        self,
2366
        filter_id: str,
2367
        *,
2368
        comment: Optional[str] = None,
2369
        name: Optional[str] = None,
2370
        term: Optional[str] = None,
2371
        filter_type: Optional[FilterType] = None,
2372
    ) -> Any:
2373
        """Modifies an existing filter.
2374
2375
        Arguments:
2376
            filter_id: UUID of the filter to be modified
2377
            comment: Comment on filter.
2378
            name: Name of filter.
2379
            term: Filter term.
2380
            filter_type: Resource type filter applies to.
2381
2382
        Returns:
2383
            The response. See :py:meth:`send_command` for details.
2384
        """
2385
        if not filter_id:
2386
            raise RequiredArgument(
2387
                function=self.modify_filter.__name__, argument='filter_id'
2388
            )
2389
2390
        cmd = XmlCommand("modify_filter")
2391
        cmd.set_attribute("filter_id", filter_id)
2392
2393
        if comment:
2394
            cmd.add_element("comment", comment)
2395
2396
        if name:
2397
            cmd.add_element("name", name)
2398
2399
        if term:
2400
            cmd.add_element("term", term)
2401
2402
        if filter_type:
2403
            if not isinstance(filter_type, self.types.FilterType):
2404
                raise InvalidArgumentType(
2405
                    function=self.modify_filter.__name__,
2406
                    argument='filter_type',
2407
                    arg_type=FilterType.__name__,
2408
                )
2409
            cmd.add_element("type", filter_type.value)
2410
2411
        return self._send_xml_command(cmd)
2412
2413
    def create_schedule(
2414
        self,
@@ 2319-2362 (lines=44) @@
2316
2317
        return self._send_xml_command(cmd)
2318
2319
    def create_filter(
2320
        self,
2321
        name: str,
2322
        *,
2323
        filter_type: Optional[FilterType] = None,
2324
        comment: Optional[str] = None,
2325
        term: Optional[str] = None,
2326
    ) -> Any:
2327
        """Create a new filter
2328
2329
        Arguments:
2330
            name: Name of the new filter
2331
            filter_type: Filter for entity type
2332
            comment: Comment for the filter
2333
            term: Filter term e.g. 'name=foo'
2334
2335
        Returns:
2336
            The response. See :py:meth:`send_command` for details.
2337
        """
2338
        if not name:
2339
            raise RequiredArgument(
2340
                function=self.create_filter.__name__, argument="name"
2341
            )
2342
2343
        cmd = XmlCommand("create_filter")
2344
        _xmlname = cmd.add_element("name", name)
2345
2346
        if comment:
2347
            cmd.add_element("comment", comment)
2348
2349
        if term:
2350
            cmd.add_element("term", term)
2351
2352
        if filter_type:
2353
            if not isinstance(filter_type, self.types.FilterType):
2354
                raise InvalidArgumentType(
2355
                    function=self.create_filter.__name__,
2356
                    argument="filter_type",
2357
                    arg_type=self.types.FilterType.__name__,
2358
                )
2359
2360
            cmd.add_element("type", filter_type.value)
2361
2362
        return self._send_xml_command(cmd)
2363
2364
    def modify_filter(
2365
        self,