Code Duplication    Length = 44-48 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

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