16
16
from stringcase import pascalcase , camelcase , snakecase
17
17
from tzlocal import get_localzone
18
18
from zoneinfo import ZoneInfoNotFoundError , ZoneInfo
19
- from .utils import ME_RESOURCE , BaseTokenBackend , FileSystemTokenBackend , Token
19
+ from .utils import ME_RESOURCE , BaseTokenBackend , FileSystemTokenBackend , Token , get_windows_tz
20
20
import datetime as dt
21
21
22
22
log = logging .getLogger (__name__ )
@@ -100,20 +100,12 @@ def __init__(self, *, protocol_url: Optional[str] = None,
100
100
self .use_default_casing : bool = True if casing_function is None else False
101
101
self .casing_function : Callable = casing_function or camelcase
102
102
103
+ # get_localzone() from tzlocal will try to get the system local timezone and if not will return UTC
104
+ self ._timezone : ZoneInfo = get_localzone ()
105
+
103
106
if timezone :
104
- if isinstance (timezone , str ):
105
- # convert string to ZoneInfo
106
- try :
107
- timezone = ZoneInfo (timezone )
108
- except ZoneInfoNotFoundError as e :
109
- log .error (f'Timezone { timezone } could not be found.' )
110
- raise e
111
- else :
112
- if not isinstance (timezone , ZoneInfo ):
113
- raise ValueError (f'The timezone parameter must be either a string or a valid ZoneInfo instance.' )
107
+ self .timezone = timezone # property setter will convert this timezone to ZoneInfo if a string is provided
114
108
115
- # get_localzone() from tzlocal will try to get the system local timezone and if not will return UTC
116
- self .timezone : ZoneInfo = timezone or get_localzone ()
117
109
self .max_top_value : int = 500 # Max $top parameter value
118
110
119
111
# define any keyword that can be different in this protocol
@@ -122,6 +114,28 @@ def __init__(self, *, protocol_url: Optional[str] = None,
122
114
# outlook = #Microsoft.OutlookServices.FileAttachment')
123
115
self .keyword_data_store : dict = {}
124
116
117
+ @property
118
+ def timezone (self ):
119
+ return self ._timezone
120
+
121
+ @timezone .setter
122
+ def timezone (self , timezone : Union [str , ZoneInfo ]):
123
+ self ._update_timezone (timezone )
124
+
125
+ def _update_timezone (self , timezone : Union [str , ZoneInfo ]):
126
+ """Sets the timezone. This is not done in the setter as you can't call super from a overriden setter """
127
+ if isinstance (timezone , str ):
128
+ # convert string to ZoneInfo
129
+ try :
130
+ timezone = ZoneInfo (timezone )
131
+ except ZoneInfoNotFoundError as e :
132
+ log .error (f'Timezone { timezone } could not be found.' )
133
+ raise e
134
+ else :
135
+ if not isinstance (timezone , ZoneInfo ):
136
+ raise ValueError (f'The timezone parameter must be either a string or a valid ZoneInfo instance.' )
137
+ self ._timezone = timezone
138
+
125
139
def get_service_keyword (self , keyword : str ) -> str :
126
140
""" Returns the data set to the key in the internal data-key dict
127
141
@@ -226,12 +240,16 @@ def __init__(self, api_version='v1.0', default_resource=None,
226
240
227
241
self .keyword_data_store ['message_type' ] = 'microsoft.graph.message'
228
242
self .keyword_data_store ['event_message_type' ] = 'microsoft.graph.eventMessage'
229
- self .keyword_data_store [
230
- 'file_attachment_type' ] = '#microsoft.graph.fileAttachment'
231
- self .keyword_data_store [
232
- 'item_attachment_type' ] = '#microsoft.graph.itemAttachment'
243
+ self .keyword_data_store ['file_attachment_type' ] = '#microsoft.graph.fileAttachment'
244
+ self .keyword_data_store ['item_attachment_type' ] = '#microsoft.graph.itemAttachment'
245
+ self .keyword_data_store ['prefer_timezone_header' ] = f'outlook.timezone="{ get_windows_tz (self ._timezone )} "'
233
246
self .max_top_value = 999 # Max $top parameter value
234
247
248
+ @Protocol .timezone .setter
249
+ def timezone (self , timezone : Union [str , ZoneInfo ]):
250
+ super ()._update_timezone (timezone )
251
+ self .keyword_data_store ['prefer_timezone_header' ] = f'outlook.timezone="{ get_windows_tz (self ._timezone )} "'
252
+
235
253
236
254
class MSOffice365Protocol (Protocol ):
237
255
""" A Microsoft Office 365 Protocol Implementation
@@ -261,18 +279,18 @@ def __init__(self, api_version='v2.0', default_resource=None,
261
279
protocol_scope_prefix = self ._oauth_scope_prefix ,
262
280
** kwargs )
263
281
264
- self .keyword_data_store [
265
- 'message_type' ] = 'Microsoft.OutlookServices.Message'
266
- self .keyword_data_store [
267
- 'event_message_type' ] = 'Microsoft.OutlookServices.EventMessage'
268
- self .keyword_data_store [
269
- 'file_attachment_type' ] = '#Microsoft.OutlookServices.' \
270
- 'FileAttachment'
271
- self .keyword_data_store [
272
- 'item_attachment_type' ] = '#Microsoft.OutlookServices.' \
273
- 'ItemAttachment'
282
+ self .keyword_data_store ['message_type' ] = 'Microsoft.OutlookServices.Message'
283
+ self .keyword_data_store ['event_message_type' ] = 'Microsoft.OutlookServices.EventMessage'
284
+ self .keyword_data_store ['file_attachment_type' ] = '#Microsoft.OutlookServices.FileAttachment'
285
+ self .keyword_data_store ['item_attachment_type' ] = '#Microsoft.OutlookServices.ItemAttachment'
286
+ self .keyword_data_store ['prefer_timezone_header' ] = f'outlook.timezone="{ get_windows_tz (self .timezone )} "'
274
287
self .max_top_value = 999 # Max $top parameter value
275
288
289
+ @Protocol .timezone .setter
290
+ def timezone (self , timezone : Union [str , ZoneInfo ]):
291
+ super ()._update_timezone (timezone )
292
+ self .keyword_data_store ['prefer_timezone_header' ] = f'outlook.timezone="{ get_windows_tz (self ._timezone )} "'
293
+
276
294
277
295
class MSBusinessCentral365Protocol (Protocol ):
278
296
""" A Microsoft Business Central Protocol Implementation
@@ -314,12 +332,16 @@ def __init__(self, api_version='v1.0', default_resource=None, environment=None,
314
332
315
333
self .keyword_data_store ['message_type' ] = 'microsoft.graph.message'
316
334
self .keyword_data_store ['event_message_type' ] = 'microsoft.graph.eventMessage'
317
- self .keyword_data_store [
318
- 'file_attachment_type' ] = '#microsoft.graph.fileAttachment'
319
- self .keyword_data_store [
320
- 'item_attachment_type' ] = '#microsoft.graph.itemAttachment'
335
+ self .keyword_data_store ['file_attachment_type' ] = '#microsoft.graph.fileAttachment'
336
+ self .keyword_data_store ['item_attachment_type' ] = '#microsoft.graph.itemAttachment'
337
+ self .keyword_data_store ['prefer_timezone_header' ] = f'outlook.timezone="{ get_windows_tz (self .timezone )} "'
321
338
self .max_top_value = 999 # Max $top parameter value
322
339
340
+ @Protocol .timezone .setter
341
+ def timezone (self , timezone : Union [str , ZoneInfo ]):
342
+ super ()._update_timezone (timezone )
343
+ self .keyword_data_store ['prefer_timezone_header' ] = f'outlook.timezone="{ get_windows_tz (self ._timezone )} "'
344
+
323
345
324
346
class Connection :
325
347
""" Handles all communication (requests) between the app and the server """
0 commit comments