|
1 | 1 | import json
|
2 | 2 | import logging
|
3 | 3 | import time
|
4 |
| -from typing import Callable, Dict, List, Optional, Tuple, Union |
| 4 | +from typing import Callable, Dict, List, Optional, Union |
5 | 5 | from urllib.parse import parse_qs, urlparse
|
6 | 6 |
|
7 | 7 | from msal import ConfidentialClientApplication, PublicClientApplication
|
|
34 | 34 |
|
35 | 35 | log = logging.getLogger(__name__)
|
36 | 36 |
|
37 |
| -O365_API_VERSION = "v2.0" |
38 |
| -GRAPH_API_VERSION = "v1.0" |
39 |
| -OAUTH_REDIRECT_URL = "https://login.microsoftonline.com/common/oauth2/nativeclient" |
| 37 | +O365_API_VERSION: str = "v2.0" |
| 38 | +GRAPH_API_VERSION: str = "v1.0" |
| 39 | +OAUTH_REDIRECT_URL: str = "https://login.microsoftonline.com/common/oauth2/nativeclient" |
40 | 40 |
|
41 | 41 | RETRIES_STATUS_LIST = (
|
42 | 42 | 429, # Status code for TooManyRequests
|
|
45 | 45 | 503,
|
46 | 46 | 504, # Server errors
|
47 | 47 | )
|
48 |
| -RETRIES_BACKOFF_FACTOR = 0.5 |
| 48 | +RETRIES_BACKOFF_FACTOR: float = 0.5 |
49 | 49 |
|
50 |
| -DEFAULT_SCOPES = { |
| 50 | +DEFAULT_SCOPES: dict[str, list[str]] = { |
51 | 51 | # wrap any scope in a 1 element tuple to avoid prefixing
|
52 | 52 | "basic": ["User.Read"],
|
53 | 53 | "mailbox": ["Mail.Read"],
|
@@ -87,9 +87,9 @@ class Protocol:
|
87 | 87 | """Base class for all protocols"""
|
88 | 88 |
|
89 | 89 | # Override these in subclass
|
90 |
| - _protocol_url = "not_defined" # Main url to request. |
91 |
| - _oauth_scope_prefix = "" # Prefix for scopes |
92 |
| - _oauth_scopes = {} # Dictionary of {scopes_name: [scope1, scope2]} |
| 90 | + _protocol_url: str = "not_defined" # Main url to request. |
| 91 | + _oauth_scope_prefix: str = "" # Prefix for scopes |
| 92 | + _oauth_scopes: dict[str, list[str]] = {} # Dictionary of {scopes_name: [scope1, scope2]} |
93 | 93 |
|
94 | 94 | def __init__(
|
95 | 95 | self,
|
@@ -144,7 +144,7 @@ def __init__(
|
144 | 144 | self.max_top_value: int = 500 # Max $top parameter value
|
145 | 145 |
|
146 | 146 | #: The in use timezone. |br| **Type:** str
|
147 |
| - self._timezone = None |
| 147 | + self._timezone: Optional[ZoneInfo] = None |
148 | 148 |
|
149 | 149 | if timezone:
|
150 | 150 | self.timezone = timezone # property setter will convert this timezone to ZoneInfo if a string is provided
|
@@ -256,7 +256,7 @@ class MSGraphProtocol(Protocol):
|
256 | 256 | _oauth_scope_prefix = "https://graph.microsoft.com/"
|
257 | 257 | _oauth_scopes = DEFAULT_SCOPES
|
258 | 258 |
|
259 |
| - def __init__(self, api_version="v1.0", default_resource=None, **kwargs): |
| 259 | + def __init__(self, api_version: str = "v1.0", default_resource: Optional[str] = None, **kwargs): |
260 | 260 | """Create a new Microsoft Graph protocol object
|
261 | 261 |
|
262 | 262 | _protocol_url = 'https://graph.microsoft.com/'
|
@@ -307,7 +307,7 @@ class MSOffice365Protocol(Protocol):
|
307 | 307 | _oauth_scope_prefix = "https://outlook.office.com/"
|
308 | 308 | _oauth_scopes = DEFAULT_SCOPES
|
309 | 309 |
|
310 |
| - def __init__(self, api_version="v2.0", default_resource=None, **kwargs): |
| 310 | + def __init__(self, api_version: str = "v2.0", default_resource: Optional[str] = None, **kwargs): |
311 | 311 | """Create a new Office 365 protocol object
|
312 | 312 |
|
313 | 313 | _protocol_url = 'https://outlook.office.com/api/'
|
@@ -362,7 +362,8 @@ class MSBusinessCentral365Protocol(Protocol):
|
362 | 362 | _protocol_scope_prefix = "https://api.businesscentral.dynamics.com/"
|
363 | 363 |
|
364 | 364 | def __init__(
|
365 |
| - self, api_version="v1.0", default_resource=None, environment=None, **kwargs |
| 365 | + self, api_version: str ="v1.0", default_resource: Optional[str] = None, |
| 366 | + environment: Optional[str] = None, **kwargs |
366 | 367 | ):
|
367 | 368 | """Create a new Microsoft Graph protocol object
|
368 | 369 |
|
@@ -421,7 +422,7 @@ class Connection:
|
421 | 422 |
|
422 | 423 | def __init__(
|
423 | 424 | self,
|
424 |
| - credentials: Tuple, |
| 425 | + credentials: tuple, |
425 | 426 | *,
|
426 | 427 | proxy_server: Optional[str] = None,
|
427 | 428 | proxy_port: Optional[int] = 8080,
|
@@ -520,7 +521,7 @@ def __init__(
|
520 | 521 | )
|
521 | 522 |
|
522 | 523 | #: The credentials for the connection. |br| **Type:** tuple
|
523 |
| - self.auth: Tuple = credentials |
| 524 | + self.auth: tuple = credentials |
524 | 525 | #: The tenant id. |br| **Type:** str
|
525 | 526 | self.tenant_id: str = tenant_id
|
526 | 527 |
|
@@ -699,7 +700,7 @@ def msal_client(self) -> MsalClientApplication:
|
699 | 700 |
|
700 | 701 | def get_authorization_url(
|
701 | 702 | self, requested_scopes: List[str], redirect_uri: Optional[str] = None, **kwargs
|
702 |
| - ) -> Tuple[str, dict]: |
| 703 | + ) -> tuple[str, dict]: |
703 | 704 | """Initializes the oauth authorization flow, getting the
|
704 | 705 | authorization url that the user must approve.
|
705 | 706 |
|
|
0 commit comments