Code Duplication    Length = 44-48 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 2781-2828 (lines=48) @@
2778
2779
        return self._send_xml_command(cmd)
2780
2781
    def modify_filter(
2782
        self,
2783
        filter_id: str,
2784
        *,
2785
        comment: Optional[str] = None,
2786
        name: Optional[str] = None,
2787
        term: Optional[str] = None,
2788
        filter_type: Optional[FilterType] = None,
2789
    ) -> Any:
2790
        """Modifies an existing filter.
2791
2792
        Arguments:
2793
            filter_id: UUID of the filter to be modified
2794
            comment: Comment on filter.
2795
            name: Name of filter.
2796
            term: Filter term.
2797
            filter_type: Resource type filter applies to.
2798
2799
        Returns:
2800
            The response. See :py:meth:`send_command` for details.
2801
        """
2802
        if not filter_id:
2803
            raise RequiredArgument(
2804
                function=self.modify_filter.__name__, argument='filter_id'
2805
            )
2806
2807
        cmd = XmlCommand("modify_filter")
2808
        cmd.set_attribute("filter_id", filter_id)
2809
2810
        if comment:
2811
            cmd.add_element("comment", comment)
2812
2813
        if name:
2814
            cmd.add_element("name", name)
2815
2816
        if term:
2817
            cmd.add_element("term", term)
2818
2819
        if filter_type:
2820
            if not isinstance(filter_type, self.types.FilterType):
2821
                raise InvalidArgumentType(
2822
                    function=self.modify_filter.__name__,
2823
                    argument='filter_type',
2824
                    arg_type=FilterType.__name__,
2825
                )
2826
            cmd.add_element("type", filter_type.value)
2827
2828
        return self._send_xml_command(cmd)
2829
2830
    def create_schedule(
2831
        self,
@@ 2736-2779 (lines=44) @@
2733
2734
        return self._send_xml_command(cmd)
2735
2736
    def create_filter(
2737
        self,
2738
        name: str,
2739
        *,
2740
        filter_type: Optional[FilterType] = None,
2741
        comment: Optional[str] = None,
2742
        term: Optional[str] = None,
2743
    ) -> Any:
2744
        """Create a new filter
2745
2746
        Arguments:
2747
            name: Name of the new filter
2748
            filter_type: Filter for entity type
2749
            comment: Comment for the filter
2750
            term: Filter term e.g. 'name=foo'
2751
2752
        Returns:
2753
            The response. See :py:meth:`send_command` for details.
2754
        """
2755
        if not name:
2756
            raise RequiredArgument(
2757
                function=self.create_filter.__name__, argument="name"
2758
            )
2759
2760
        cmd = XmlCommand("create_filter")
2761
        _xmlname = cmd.add_element("name", name)
2762
2763
        if comment:
2764
            cmd.add_element("comment", comment)
2765
2766
        if term:
2767
            cmd.add_element("term", term)
2768
2769
        if filter_type:
2770
            if not isinstance(filter_type, self.types.FilterType):
2771
                raise InvalidArgumentType(
2772
                    function=self.create_filter.__name__,
2773
                    argument="filter_type",
2774
                    arg_type=self.types.FilterType.__name__,
2775
                )
2776
2777
            cmd.add_element("type", filter_type.value)
2778
2779
        return self._send_xml_command(cmd)
2780
2781
    def modify_filter(
2782
        self,