Code Duplication    Length = 78-78 lines in 2 locations

gvm/protocols/gmpv8/gmpv8.py 1 location

@@ 977-1054 (lines=78) @@
974
975
        return self._send_xml_command(cmd)
976
977
    def create_schedule(
978
        self,
979
        name: str,
980
        icalendar: str,
981
        timezone: str,
982
        *,
983
        comment: Optional[str] = None,
984
    ) -> Any:
985
        """Create a new schedule based in `iCalendar`_ data.
986
987
        Example:
988
            Requires https://pypi.org/project/icalendar/
989
990
            .. code-block:: python
991
992
                import pytz
993
994
                from datetime import datetime
995
996
                from icalendar import Calendar, Event
997
998
                cal = Calendar()
999
1000
                cal.add('prodid', '-//Foo Bar//')
1001
                cal.add('version', '2.0')
1002
1003
                event = Event()
1004
                event.add('dtstamp', datetime.now(tz=pytz.UTC))
1005
                event.add('dtstart', datetime(2020, 1, 1, tzinfo=pytz.utc))
1006
1007
                cal.add_component(event)
1008
1009
                gmp.create_schedule(
1010
                    name="My Schedule",
1011
                    icalendar=cal.to_ical(),
1012
                    timezone='UTC'
1013
                )
1014
1015
1016
        Arguments:
1017
            name: Name of the new schedule
1018
            icalendar: `iCalendar`_ (RFC 5545) based data.
1019
            timezone: Timezone to use for the icalender events e.g
1020
                Europe/Berlin. If the datetime values in the icalendar data are
1021
                missing timezone information this timezone gets applied.
1022
                Otherwise the datetime values from the icalendar data are
1023
                displayed in this timezone
1024
            comment: Comment on schedule.
1025
1026
        Returns:
1027
            The response. See :py:meth:`send_command` for details.
1028
1029
        .. _iCalendar:
1030
            https://tools.ietf.org/html/rfc5545
1031
        """
1032
        if not name:
1033
            raise RequiredArgument(
1034
                function=self.create_schedule.__name__, argument='name'
1035
            )
1036
        if not icalendar:
1037
            raise RequiredArgument(
1038
                function=self.create_schedule.__name__, argument='icalendar'
1039
            )
1040
        if not timezone:
1041
            raise RequiredArgument(
1042
                function=self.create_schedule.__name__, argument='timezone'
1043
            )
1044
1045
        cmd = XmlCommand("create_schedule")
1046
1047
        cmd.add_element("name", name)
1048
        cmd.add_element("icalendar", icalendar)
1049
        cmd.add_element("timezone", timezone)
1050
1051
        if comment:
1052
            cmd.add_element("comment", comment)
1053
1054
        return self._send_xml_command(cmd)
1055
1056
    def modify_schedule(
1057
        self,

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 3178-3255 (lines=78) @@
3175
3176
        return self._send_xml_command(cmd)
3177
3178
    def create_schedule(
3179
        self,
3180
        name: str,
3181
        icalendar: str,
3182
        timezone: str,
3183
        *,
3184
        comment: Optional[str] = None,
3185
    ) -> Any:
3186
        """Create a new schedule based in `iCalendar`_ data.
3187
3188
        Example:
3189
            Requires https://pypi.org/project/icalendar/
3190
3191
            .. code-block:: python
3192
3193
                import pytz
3194
3195
                from datetime import datetime
3196
3197
                from icalendar import Calendar, Event
3198
3199
                cal = Calendar()
3200
3201
                cal.add('prodid', '-//Foo Bar//')
3202
                cal.add('version', '2.0')
3203
3204
                event = Event()
3205
                event.add('dtstamp', datetime.now(tz=pytz.UTC))
3206
                event.add('dtstart', datetime(2020, 1, 1, tzinfo=pytz.utc))
3207
3208
                cal.add_component(event)
3209
3210
                gmp.create_schedule(
3211
                    name="My Schedule",
3212
                    icalendar=cal.to_ical(),
3213
                    timezone='UTC'
3214
                )
3215
3216
3217
        Arguments:
3218
            name: Name of the new schedule
3219
            icalendar: `iCalendar`_ (RFC 5545) based data.
3220
            timezone: Timezone to use for the icalender events e.g
3221
                Europe/Berlin. If the datetime values in the icalendar data are
3222
                missing timezone information this timezone gets applied.
3223
                Otherwise the datetime values from the icalendar data are
3224
                displayed in this timezone
3225
            comment: Comment on schedule.
3226
3227
        Returns:
3228
            The response. See :py:meth:`send_command` for details.
3229
3230
        .. _iCalendar:
3231
            https://tools.ietf.org/html/rfc5545
3232
        """
3233
        if not name:
3234
            raise RequiredArgument(
3235
                function=self.create_schedule.__name__, argument='name'
3236
            )
3237
        if not icalendar:
3238
            raise RequiredArgument(
3239
                function=self.create_schedule.__name__, argument='icalendar'
3240
            )
3241
        if not timezone:
3242
            raise RequiredArgument(
3243
                function=self.create_schedule.__name__, argument='timezone'
3244
            )
3245
3246
        cmd = XmlCommand("create_schedule")
3247
3248
        cmd.add_element("name", name)
3249
        cmd.add_element("icalendar", icalendar)
3250
        cmd.add_element("timezone", timezone)
3251
3252
        if comment:
3253
            cmd.add_element("comment", comment)
3254
3255
        return self._send_xml_command(cmd)
3256
3257
    def modify_schedule(
3258
        self,