Code Duplication    Length = 43-43 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 2111-2153 (lines=43) @@
2108
2109
        return self._send_xml_command(cmd)
2110
2111
    def import_report(
2112
        self,
2113
        report: str,
2114
        *,
2115
        task_id: Optional[str] = None,
2116
        in_assets: Optional[bool] = None,
2117
    ) -> Any:
2118
        """Import a Report from XML
2119
2120
        Arguments:
2121
            report: Report XML as string to import. This XML must contain
2122
                a :code:`<report>` root element.
2123
            task_id: UUID of task to import report to
2124
            in_asset: Whether to create or update assets using the report
2125
2126
        Returns:
2127
            The response. See :py:meth:`send_command` for details.
2128
        """
2129
        if not report:
2130
            raise RequiredArgument(
2131
                function=self.import_report.__name__, argument='report'
2132
            )
2133
2134
        cmd = XmlCommand("create_report")
2135
2136
        if task_id:
2137
            cmd.add_element("task", attrs={"id": task_id})
2138
        else:
2139
            raise RequiredArgument(
2140
                function=self.import_report.__name__, argument='task_id'
2141
            )
2142
2143
        if in_assets is not None:
2144
            cmd.add_element("in_assets", _to_bool(in_assets))
2145
2146
        try:
2147
            cmd.append_xml_str(report)
2148
        except etree.XMLSyntaxError as e:
2149
            raise InvalidArgument(
2150
                "Invalid xml passed as report to import_report {}".format(e)
2151
            ) from None
2152
2153
        return self._send_xml_command(cmd)
2154
2155
    def create_agent(
2156
        self,

gvm/protocols/gmpv9/gmpv9.py 1 location

@@ 1984-2026 (lines=43) @@
1981
1982
        return self._send_xml_command(cmd)
1983
1984
    def import_report(
1985
        self,
1986
        report: str,
1987
        *,
1988
        task_id: Optional[str] = None,
1989
        in_assets: Optional[bool] = None,
1990
    ) -> Any:
1991
        """Import a Report from XML
1992
1993
        Arguments:
1994
            report: Report XML as string to import. This XML must contain
1995
                a :code:`<report>` root element.
1996
            task_id: UUID of task to import report to
1997
            in_asset: Whether to create or update assets using the report
1998
1999
        Returns:
2000
            The response. See :py:meth:`send_command` for details.
2001
        """
2002
        if not report:
2003
            raise RequiredArgument(
2004
                function=self.import_report.__name__, argument='report'
2005
            )
2006
2007
        cmd = XmlCommand("create_report")
2008
2009
        if task_id:
2010
            cmd.add_element("task", attrs={"id": task_id})
2011
        else:
2012
            raise RequiredArgument(
2013
                function=self.import_report.__name__, argument='task_id'
2014
            )
2015
2016
        if in_assets is not None:
2017
            cmd.add_element("in_assets", _to_bool(in_assets))
2018
2019
        try:
2020
            cmd.append_xml_str(report)
2021
        except etree.XMLSyntaxError as e:
2022
            raise InvalidArgument(
2023
                "Invalid xml passed as report to import_report {}".format(e)
2024
            ) from None
2025
2026
        return self._send_xml_command(cmd)
2027