Code Duplication    Length = 78-78 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 3146-3223 (lines=78) @@
3143
3144
        return self._send_xml_command(cmd)
3145
3146
    def create_schedule(
3147
        self,
3148
        name: str,
3149
        icalendar: str,
3150
        timezone: str,
3151
        *,
3152
        comment: Optional[str] = None,
3153
    ) -> Any:
3154
        """Create a new schedule based in `iCalendar`_ data.
3155
3156
        Example:
3157
            Requires https://pypi.org/project/icalendar/
3158
3159
            .. code-block:: python
3160
3161
                import pytz
3162
3163
                from datetime import datetime
3164
3165
                from icalendar import Calendar, Event
3166
3167
                cal = Calendar()
3168
3169
                cal.add('prodid', '-//Foo Bar//')
3170
                cal.add('version', '2.0')
3171
3172
                event = Event()
3173
                event.add('dtstamp', datetime.now(tz=pytz.UTC))
3174
                event.add('dtstart', datetime(2020, 1, 1, tzinfo=pytz.utc))
3175
3176
                cal.add_component(event)
3177
3178
                gmp.create_schedule(
3179
                    name="My Schedule",
3180
                    icalendar=cal.to_ical(),
3181
                    timezone='UTC'
3182
                )
3183
3184
3185
        Arguments:
3186
            name: Name of the new schedule
3187
            icalendar: `iCalendar`_ (RFC 5545) based data.
3188
            timezone: Timezone to use for the icalender events e.g
3189
                Europe/Berlin. If the datetime values in the icalendar data are
3190
                missing timezone information this timezone gets applied.
3191
                Otherwise the datetime values from the icalendar data are
3192
                displayed in this timezone
3193
            comment: Comment on schedule.
3194
3195
        Returns:
3196
            The response. See :py:meth:`send_command` for details.
3197
3198
        .. _iCalendar:
3199
            https://tools.ietf.org/html/rfc5545
3200
        """
3201
        if not name:
3202
            raise RequiredArgument(
3203
                function=self.create_schedule.__name__, argument='name'
3204
            )
3205
        if not icalendar:
3206
            raise RequiredArgument(
3207
                function=self.create_schedule.__name__, argument='icalendar'
3208
            )
3209
        if not timezone:
3210
            raise RequiredArgument(
3211
                function=self.create_schedule.__name__, argument='timezone'
3212
            )
3213
3214
        cmd = XmlCommand("create_schedule")
3215
3216
        cmd.add_element("name", name)
3217
        cmd.add_element("icalendar", icalendar)
3218
        cmd.add_element("timezone", timezone)
3219
3220
        if comment:
3221
            cmd.add_element("comment", comment)
3222
3223
        return self._send_xml_command(cmd)
3224
3225
    def modify_schedule(
3226
        self,

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,