44# license information.
55# -------------------------------------------------------------------------
66from enum import Enum
7+ from typing import Dict , Any
78from datetime import datetime
8- from typing import Self
99from dataclasses import dataclass
1010from email .utils import parsedate_to_datetime
1111
@@ -18,7 +18,16 @@ class RecurrencePatternType(str, Enum):
1818 DAILY = "Daily"
1919 WEEKLY = "Weekly"
2020
21- def from_str (value : str ) -> Self :
21+ @staticmethod
22+ def from_str (value : str ) -> "RecurrencePatternType" :
23+ """
24+ Get the RecurrencePatternType from the string value.
25+
26+ :param value: The string value.
27+ :type value: str
28+ :return: The RecurrencePatternType.
29+ :rtype: RecurrencePatternType
30+ """
2231 if value == "Daily" :
2332 return RecurrencePatternType .DAILY
2433 if value == "Weekly" :
@@ -35,7 +44,16 @@ class RecurrenceRangeType(str, Enum):
3544 END_DATE = "EndDate"
3645 NUMBERED = "Numbered"
3746
38- def from_str (value : str ) -> Self :
47+ @staticmethod
48+ def from_str (value : str ) -> "RecurrenceRangeType" :
49+ """
50+ Get the RecurrenceRangeType from the string value.
51+
52+ :param value: The string value.
53+ :type value: str
54+ :return: The RecurrenceRangeType.
55+ :rtype: RecurrenceRangeType
56+ """
3957 if value == "NoEnd" :
4058 return RecurrenceRangeType .NO_END
4159 if value == "EndDate" :
@@ -44,36 +62,40 @@ def from_str(value: str) -> Self:
4462 return RecurrenceRangeType .NUMBERED
4563 raise ValueError (f"Invalid value: { value } " )
4664
47- class RecurrencePattern :
65+
66+ class RecurrencePattern : # pylint: disable=too-few-public-methods
4867 """
4968 The recurrence pattern settings.
5069 """
5170
52- def __init__ (self , pattern_data : dict [str : any ]):
71+ def __init__ (self , pattern_data : Dict [str , Any ]):
5372 self .type = RecurrencePatternType .from_str (pattern_data .get ("Type" , "Daily" ))
5473 self .interval = pattern_data .get ("Interval" , 1 )
5574 self .days_of_week = pattern_data .get ("DaysOfWeek" , [])
5675 self .first_day_of_week = pattern_data .get ("FirstDayOfWeek" , 7 )
5776
58- class RecurrenceRange :
77+
78+ class RecurrenceRange : # pylint: disable=too-few-public-methods
5979 """
6080 The recurrence range settings.
6181 """
6282
63- def __init__ (self , range_data : dict [str : any ]):
83+ def __init__ (self , range_data : Dict [str , Any ]):
6484 self .type = RecurrenceRangeType .from_str (range_data .get ("Type" , "NoEnd" ))
65- if range_data .get ("EndDate" ):
66- self .end_date = parsedate_to_datetime (range_data .get ("EndDate" ))
85+ if range_data .get ("EndDate" ) and isinstance (range_data .get ("EndDate" ), str ):
86+ end_date_str = range_data .get ("EndDate" , "" )
87+ self .end_date = parsedate_to_datetime (end_date_str ) if end_date_str else None
6788 self .num_of_occurrences = range_data .get ("NumberOfOccurrences" )
6889
69- class Recurrence :
90+
91+ class Recurrence : # pylint: disable=too-few-public-methods
7092 """
7193 The recurrence settings.
7294 """
7395
74- def __init__ (self , recurrence_data : dict [str : any ]):
75- self .pattern = RecurrencePattern (recurrence_data .get ("Pattern" ))
76- self .range = RecurrenceRange (recurrence_data .get ("Range" ))
96+ def __init__ (self , recurrence_data : Dict [str , Any ]):
97+ self .pattern = RecurrencePattern (recurrence_data .get ("Pattern" , {} ))
98+ self .range = RecurrenceRange (recurrence_data .get ("Range" , {} ))
7799
78100
79101@dataclass
0 commit comments