Code Duplication    Length = 44-48 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 1741-1788 (lines=48) @@
1738
1739
        return self._send_xml_command(cmd)
1740
1741
    def modify_filter(
1742
        self,
1743
        filter_id: str,
1744
        *,
1745
        comment: Optional[str] = None,
1746
        name: Optional[str] = None,
1747
        term: Optional[str] = None,
1748
        filter_type: Optional[FilterType] = None,
1749
    ) -> Any:
1750
        """Modifies an existing filter.
1751
1752
        Arguments:
1753
            filter_id: UUID of the filter to be modified
1754
            comment: Comment on filter.
1755
            name: Name of filter.
1756
            term: Filter term.
1757
            filter_type: Resource type filter applies to.
1758
1759
        Returns:
1760
            The response. See :py:meth:`send_command` for details.
1761
        """
1762
        if not filter_id:
1763
            raise RequiredArgument(
1764
                function=self.modify_filter.__name__, argument='filter_id'
1765
            )
1766
1767
        cmd = XmlCommand("modify_filter")
1768
        cmd.set_attribute("filter_id", filter_id)
1769
1770
        if comment:
1771
            cmd.add_element("comment", comment)
1772
1773
        if name:
1774
            cmd.add_element("name", name)
1775
1776
        if term:
1777
            cmd.add_element("term", term)
1778
1779
        if filter_type:
1780
            if not isinstance(filter_type, self.types.FilterType):
1781
                raise InvalidArgumentType(
1782
                    function=self.modify_filter.__name__,
1783
                    argument='filter_type',
1784
                    arg_type=FilterType.__name__,
1785
                )
1786
            cmd.add_element("type", filter_type.value)
1787
1788
        return self._send_xml_command(cmd)
1789
1790
    def create_schedule(
1791
        self,
@@ 1696-1739 (lines=44) @@
1693
1694
        return self._send_xml_command(cmd)
1695
1696
    def create_filter(
1697
        self,
1698
        name: str,
1699
        *,
1700
        filter_type: Optional[FilterType] = None,
1701
        comment: Optional[str] = None,
1702
        term: Optional[str] = None,
1703
    ) -> Any:
1704
        """Create a new filter
1705
1706
        Arguments:
1707
            name: Name of the new filter
1708
            filter_type: Filter for entity type
1709
            comment: Comment for the filter
1710
            term: Filter term e.g. 'name=foo'
1711
1712
        Returns:
1713
            The response. See :py:meth:`send_command` for details.
1714
        """
1715
        if not name:
1716
            raise RequiredArgument(
1717
                function=self.create_filter.__name__, argument="name"
1718
            )
1719
1720
        cmd = XmlCommand("create_filter")
1721
        _xmlname = cmd.add_element("name", name)
1722
1723
        if comment:
1724
            cmd.add_element("comment", comment)
1725
1726
        if term:
1727
            cmd.add_element("term", term)
1728
1729
        if filter_type:
1730
            if not isinstance(filter_type, self.types.FilterType):
1731
                raise InvalidArgumentType(
1732
                    function=self.create_filter.__name__,
1733
                    argument="filter_type",
1734
                    arg_type=self.types.FilterType.__name__,
1735
                )
1736
1737
            cmd.add_element("type", filter_type.value)
1738
1739
        return self._send_xml_command(cmd)
1740
1741
    def modify_filter(
1742
        self,