Code Duplication    Length = 44-48 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 1318-1365 (lines=48) @@
1315
1316
        return self._send_xml_command(cmd)
1317
1318
    def modify_filter(
1319
        self,
1320
        filter_id: str,
1321
        *,
1322
        comment: Optional[str] = None,
1323
        name: Optional[str] = None,
1324
        term: Optional[str] = None,
1325
        filter_type: Optional[FilterType] = None,
1326
    ) -> Any:
1327
        """Modifies an existing filter.
1328
1329
        Arguments:
1330
            filter_id: UUID of the filter to be modified
1331
            comment: Comment on filter.
1332
            name: Name of filter.
1333
            term: Filter term.
1334
            filter_type: Resource type filter applies to.
1335
1336
        Returns:
1337
            The response. See :py:meth:`send_command` for details.
1338
        """
1339
        if not filter_id:
1340
            raise RequiredArgument(
1341
                function=self.modify_filter.__name__, argument='filter_id'
1342
            )
1343
1344
        cmd = XmlCommand("modify_filter")
1345
        cmd.set_attribute("filter_id", filter_id)
1346
1347
        if comment:
1348
            cmd.add_element("comment", comment)
1349
1350
        if name:
1351
            cmd.add_element("name", name)
1352
1353
        if term:
1354
            cmd.add_element("term", term)
1355
1356
        if filter_type:
1357
            if not isinstance(filter_type, self.types.FilterType):
1358
                raise InvalidArgumentType(
1359
                    function=self.modify_filter.__name__,
1360
                    argument='filter_type',
1361
                    arg_type=FilterType.__name__,
1362
                )
1363
            cmd.add_element("type", filter_type.value)
1364
1365
        return self._send_xml_command(cmd)
1366
1367
    def create_schedule(
1368
        self,
@@ 1273-1316 (lines=44) @@
1270
1271
        return self._send_xml_command(cmd)
1272
1273
    def create_filter(
1274
        self,
1275
        name: str,
1276
        *,
1277
        filter_type: Optional[FilterType] = None,
1278
        comment: Optional[str] = None,
1279
        term: Optional[str] = None,
1280
    ) -> Any:
1281
        """Create a new filter
1282
1283
        Arguments:
1284
            name: Name of the new filter
1285
            filter_type: Filter for entity type
1286
            comment: Comment for the filter
1287
            term: Filter term e.g. 'name=foo'
1288
1289
        Returns:
1290
            The response. See :py:meth:`send_command` for details.
1291
        """
1292
        if not name:
1293
            raise RequiredArgument(
1294
                function=self.create_filter.__name__, argument="name"
1295
            )
1296
1297
        cmd = XmlCommand("create_filter")
1298
        _xmlname = cmd.add_element("name", name)
1299
1300
        if comment:
1301
            cmd.add_element("comment", comment)
1302
1303
        if term:
1304
            cmd.add_element("term", term)
1305
1306
        if filter_type:
1307
            if not isinstance(filter_type, self.types.FilterType):
1308
                raise InvalidArgumentType(
1309
                    function=self.create_filter.__name__,
1310
                    argument="filter_type",
1311
                    arg_type=self.types.FilterType.__name__,
1312
                )
1313
1314
            cmd.add_element("type", filter_type.value)
1315
1316
        return self._send_xml_command(cmd)
1317
1318
    def modify_filter(
1319
        self,