Code Duplication    Length = 44-48 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 2693-2740 (lines=48) @@
2690
2691
        return self._send_xml_command(cmd)
2692
2693
    def modify_filter(
2694
        self,
2695
        filter_id: str,
2696
        *,
2697
        comment: Optional[str] = None,
2698
        name: Optional[str] = None,
2699
        term: Optional[str] = None,
2700
        filter_type: Optional[FilterType] = None,
2701
    ) -> Any:
2702
        """Modifies an existing filter.
2703
2704
        Arguments:
2705
            filter_id: UUID of the filter to be modified
2706
            comment: Comment on filter.
2707
            name: Name of filter.
2708
            term: Filter term.
2709
            filter_type: Resource type filter applies to.
2710
2711
        Returns:
2712
            The response. See :py:meth:`send_command` for details.
2713
        """
2714
        if not filter_id:
2715
            raise RequiredArgument(
2716
                function=self.modify_filter.__name__, argument='filter_id'
2717
            )
2718
2719
        cmd = XmlCommand("modify_filter")
2720
        cmd.set_attribute("filter_id", filter_id)
2721
2722
        if comment:
2723
            cmd.add_element("comment", comment)
2724
2725
        if name:
2726
            cmd.add_element("name", name)
2727
2728
        if term:
2729
            cmd.add_element("term", term)
2730
2731
        if filter_type:
2732
            if not isinstance(filter_type, self.types.FilterType):
2733
                raise InvalidArgumentType(
2734
                    function=self.modify_filter.__name__,
2735
                    argument='filter_type',
2736
                    arg_type=FilterType.__name__,
2737
                )
2738
            cmd.add_element("type", filter_type.value)
2739
2740
        return self._send_xml_command(cmd)
2741
2742
    def create_schedule(
2743
        self,
@@ 2648-2691 (lines=44) @@
2645
2646
        return self._send_xml_command(cmd)
2647
2648
    def create_filter(
2649
        self,
2650
        name: str,
2651
        *,
2652
        filter_type: Optional[FilterType] = None,
2653
        comment: Optional[str] = None,
2654
        term: Optional[str] = None,
2655
    ) -> Any:
2656
        """Create a new filter
2657
2658
        Arguments:
2659
            name: Name of the new filter
2660
            filter_type: Filter for entity type
2661
            comment: Comment for the filter
2662
            term: Filter term e.g. 'name=foo'
2663
2664
        Returns:
2665
            The response. See :py:meth:`send_command` for details.
2666
        """
2667
        if not name:
2668
            raise RequiredArgument(
2669
                function=self.create_filter.__name__, argument="name"
2670
            )
2671
2672
        cmd = XmlCommand("create_filter")
2673
        _xmlname = cmd.add_element("name", name)
2674
2675
        if comment:
2676
            cmd.add_element("comment", comment)
2677
2678
        if term:
2679
            cmd.add_element("term", term)
2680
2681
        if filter_type:
2682
            if not isinstance(filter_type, self.types.FilterType):
2683
                raise InvalidArgumentType(
2684
                    function=self.create_filter.__name__,
2685
                    argument="filter_type",
2686
                    arg_type=self.types.FilterType.__name__,
2687
                )
2688
2689
            cmd.add_element("type", filter_type.value)
2690
2691
        return self._send_xml_command(cmd)
2692
2693
    def modify_filter(
2694
        self,