Skip to content

Commit 1778281

Browse files
committed
Fix Python 3.8 compatibility issue and normalize string formatting in this PR
1 parent 0c7b29b commit 1778281

26 files changed

+276
-245
lines changed

firebase_admin/__init__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
"""Firebase Admin SDK for Python."""
16-
import datetime
1716
import json
1817
import os
1918
import threading
@@ -26,11 +25,10 @@
2625
from firebase_admin import _typing
2726

2827

29-
_T = typing.TypeVar("_T")
28+
_T = typing.TypeVar('_T')
3029

31-
_apps: typing.Dict[str, "App"] = {}
30+
_apps: typing.Dict[str, 'App'] = {}
3231
_apps_lock = threading.RLock()
33-
_clock = lambda: datetime.datetime.now(datetime.timezone.utc)
3432

3533
_DEFAULT_APP_NAME = '[DEFAULT]'
3634
_FIREBASE_CONFIG_ENV_VAR = 'FIREBASE_CONFIG'
@@ -40,8 +38,8 @@
4038
def initialize_app(
4139
credential: typing.Optional[_typing.CredentialLike] = None,
4240
options: typing.Optional[typing.Dict[str, typing.Any]] = None,
43-
name: str = _DEFAULT_APP_NAME
44-
) -> "App":
41+
name: str = _DEFAULT_APP_NAME,
42+
) -> 'App':
4543
"""Initializes and returns a new App instance.
4644
4745
Creates a new App instance using the specified options
@@ -94,7 +92,7 @@ def initialize_app(
9492
'you call initialize_app().').format(name))
9593

9694

97-
def delete_app(app: "App") -> None:
95+
def delete_app(app: 'App') -> None:
9896
"""Gracefully deletes an App instance.
9997
10098
Args:
@@ -122,7 +120,7 @@ def delete_app(app: "App") -> None:
122120
'second argument.').format(app.name))
123121

124122

125-
def get_app(name: str = _DEFAULT_APP_NAME) -> "App":
123+
def get_app(name: str = _DEFAULT_APP_NAME) -> 'App':
126124
"""Retrieves an App instance by name.
127125
128126
Args:
@@ -280,7 +278,7 @@ def _lookup_project_id(self) -> typing.Optional[str]:
280278
project_id: typing.Optional[str] = self._options.get('projectId')
281279
if not project_id:
282280
try:
283-
project_id = getattr(self._credential, "project_id")
281+
project_id = getattr(self._credential, 'project_id')
284282
except (AttributeError, DefaultCredentialsError):
285283
pass
286284
if not project_id:

firebase_admin/_auth_providers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from firebase_admin import _user_mgt
2727

2828

29-
_ProviderConfigT = typing_extensions.TypeVar("_ProviderConfigT", bound="ProviderConfig", default="ProviderConfig")
29+
_ProviderConfigT = typing_extensions.TypeVar('_ProviderConfigT', bound='ProviderConfig', default='ProviderConfig')
3030

3131

3232
MAX_LIST_CONFIGS_RESULTS = 100
@@ -119,7 +119,7 @@ def __init__(
119119
self,
120120
download: typing.Callable[[typing.Optional[str], int], typing.Dict[str, _typing.Json]],
121121
page_token: typing.Optional[str],
122-
max_results: int
122+
max_results: int,
123123
) -> None:
124124
self._download = download
125125
self._max_results = max_results
@@ -151,7 +151,7 @@ def get_next_page(self) -> typing.Optional[typing_extensions.Self]:
151151
return self.__class__(self._download, self.next_page_token, self._max_results)
152152
return None
153153

154-
def iterate_all(self) -> "_ProviderConfigIterator[_ProviderConfigT]":
154+
def iterate_all(self) -> '_ProviderConfigIterator[_ProviderConfigT]':
155155
"""Retrieves an iterator for provider configs.
156156
157157
Returned iterator will iterate through all the provider configs in the Firebase project

firebase_admin/_auth_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from firebase_admin import _utils
2828

2929

30-
_PageT = typing.TypeVar("_PageT", bound=_typing.Page)
30+
_PageT = typing.TypeVar('_PageT', bound=_typing.Page)
3131

3232
EMULATOR_HOST_ENV_VAR = 'FIREBASE_AUTH_EMULATOR_HOST'
3333
MAX_CLAIMS_PAYLOAD_SIZE = 1000
@@ -381,7 +381,7 @@ def __init__(
381381
self,
382382
message: str,
383383
cause: typing.Optional[Exception],
384-
http_response: typing.Optional[requests.Response]
384+
http_response: typing.Optional[requests.Response],
385385
) -> None:
386386
exceptions.AlreadyExistsError.__init__(self, message, cause, http_response)
387387

@@ -395,7 +395,7 @@ def __init__(
395395
self,
396396
message: str,
397397
cause: typing.Optional[Exception],
398-
http_response: typing.Optional[requests.Response]
398+
http_response: typing.Optional[requests.Response],
399399
) -> None:
400400
exceptions.AlreadyExistsError.__init__(self, message, cause, http_response)
401401

@@ -412,7 +412,7 @@ def __init__(
412412
self,
413413
message: str,
414414
cause: typing.Optional[Exception],
415-
http_response: typing.Optional[requests.Response]
415+
http_response: typing.Optional[requests.Response],
416416
) -> None:
417417
exceptions.PermissionDeniedError.__init__(self, message, cause, http_response)
418418

@@ -426,7 +426,7 @@ def __init__(
426426
self,
427427
message: str,
428428
cause: typing.Optional[Exception],
429-
http_response: typing.Optional[requests.Response]
429+
http_response: typing.Optional[requests.Response],
430430
) -> None:
431431
exceptions.InvalidArgumentError.__init__(self, message, cause, http_response)
432432

@@ -637,7 +637,7 @@ def _parse_error_body(response: requests.Response) -> typing.Tuple[typing.Option
637637
def _build_error_message(
638638
code: str,
639639
exc_type: typing.Optional[_typing.FirebaseErrorFactory],
640-
custom_message: typing.Optional[str]
640+
custom_message: typing.Optional[str],
641641
) -> str:
642642
default_message: str = getattr(exc_type, 'default_message', 'Error while calling Auth service')
643643
ext = ' {0}'.format(custom_message) if custom_message else ''

firebase_admin/_gapic_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
from firebase_admin import _typing
2727
from firebase_admin import _utils
2828

29+
2930
def handle_platform_error_from_googleapiclient(
3031
error: Exception,
31-
handle_func: typing.Optional[_typing.GoogleAPIErrorHandler] = None
32+
handle_func: typing.Optional[_typing.GoogleAPIErrorHandler] = None,
3233
) -> exceptions.FirebaseError:
3334
"""Constructs a ``FirebaseError`` from the given googleapiclient error.
3435
@@ -61,7 +62,7 @@ def _handle_func_googleapiclient(
6162
error: Exception,
6263
message: str,
6364
error_dict: typing.Dict[str, typing.Any],
64-
http_response: requests.Response
65+
http_response: requests.Response,
6566
) -> exceptions.FirebaseError:
6667
"""Constructs a ``FirebaseError`` from the given GCP error.
6768

firebase_admin/_http_client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
logger = logging.getLogger(__name__)
4040

41-
_AnyT = typing_extensions.TypeVar("_AnyT", default=typing.Any)
41+
_AnyT = typing_extensions.TypeVar('_AnyT', default=typing.Any)
4242

4343
if hasattr(retry.Retry.DEFAULT, 'allowed_methods'):
4444
_ANY_METHOD: typing.Dict[str, typing.Any] = {'allowed_methods': None}
@@ -55,8 +55,6 @@
5555
DEFAULT_HTTPX_RETRY_CONFIG = _retry.HttpxRetry(
5656
max_retries=4, status_forcelist=[500, 503], backoff_factor=0.5)
5757

58-
59-
6058
DEFAULT_TIMEOUT_SECONDS = 120
6159

6260
METRICS_HEADERS = {
@@ -75,7 +73,7 @@ def __init__(
7573
credential: typing.Optional[google.auth.credentials.Credentials] = None,
7674
session: typing.Optional[requests.Session] = None,
7775
base_url: str = '',
78-
headers: typing.Optional["_typing.HeadersLike"] = None,
76+
headers: typing.Optional['_typing.HeadersLike'] = None,
7977
retries: retry.Retry = DEFAULT_RETRY_CONFIG,
8078
timeout: int = DEFAULT_TIMEOUT_SECONDS,
8179
) -> None:
@@ -181,9 +179,9 @@ def close(self) -> None:
181179
self._session = None
182180

183181

184-
class JsonHttpClient(HttpClient[typing.Dict[str ,"_typing.Json"]]):
182+
class JsonHttpClient(HttpClient[typing.Dict[str, '_typing.Json']]):
185183
"""An HTTP client that parses response messages as JSON."""
186-
def parse_body(self, resp: requests.Response) -> typing.Dict[str ,"_typing.Json"]:
184+
def parse_body(self, resp: requests.Response) -> typing.Dict[str, '_typing.Json']:
187185
return resp.json()
188186

189187

firebase_admin/_messaging_encoder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
from firebase_admin import _messaging_utils
2525

26-
_K = typing.TypeVar("_K")
27-
_V = typing.TypeVar("_V")
26+
_K = typing.TypeVar('_K')
27+
_V = typing.TypeVar('_V')
2828

2929

3030
class Message:
@@ -537,7 +537,7 @@ def encode_webpush_notification(
537537
@classmethod
538538
def encode_webpush_notification_actions(
539539
cls,
540-
actions: typing.Optional[typing.List[_messaging_utils.WebpushNotificationAction]]
540+
actions: typing.Optional[typing.List[_messaging_utils.WebpushNotificationAction]],
541541
) -> typing.Optional[typing.List[typing.Dict[str, str]]]:
542542
"""Encodes a list of ``WebpushNotificationActions`` into JSON."""
543543
if actions is None:

firebase_admin/_messaging_utils.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ class AndroidConfig:
7272
def __init__(
7373
self,
7474
collapse_key: typing.Optional[str] = None,
75-
priority: typing.Optional[typing.Literal["high", "normal"]] = None,
75+
priority: typing.Optional[typing.Literal['high', 'normal']] = None,
7676
ttl: typing.Optional[typing.Union[numbers.Real, datetime.timedelta]] = None,
7777
restricted_package_name: typing.Optional[str] = None,
7878
data: typing.Optional[typing.Dict[str, str]] = None,
79-
notification: typing.Optional["AndroidNotification"] = None,
80-
fcm_options: typing.Optional["AndroidFCMOptions"] = None,
79+
notification: typing.Optional['AndroidNotification'] = None,
80+
fcm_options: typing.Optional['AndroidFCMOptions'] = None,
8181
direct_boot_ok: typing.Optional[bool] = None,
8282
) -> None:
8383
self.collapse_key = collapse_key
@@ -197,15 +197,15 @@ def __init__(
197197
sticky: typing.Optional[bool] = None,
198198
event_timestamp: typing.Optional[datetime.datetime] = None,
199199
local_only: typing.Optional[Incomplete] = None,
200-
priority: typing.Optional[typing.Literal["default", "min", "low", "high", "max", "normal"]] = None,
200+
priority: typing.Optional[typing.Literal['default', 'min', 'low', 'high', 'max', 'normal']] = None,
201201
vibrate_timings_millis: typing.Optional[float] = None,
202202
default_vibrate_timings: typing.Optional[bool] = None,
203203
default_sound: typing.Optional[bool] = None,
204-
light_settings: typing.Optional["LightSettings"] = None,
204+
light_settings: typing.Optional['LightSettings'] = None,
205205
default_light_settings: typing.Optional[bool] = None,
206-
visibility: typing.Optional[typing.Literal["private", "public", "secret"]] = None,
206+
visibility: typing.Optional[typing.Literal['private', 'public', 'secret']] = None,
207207
notification_count: typing.Optional[int] = None,
208-
proxy: typing.Optional[typing.Literal["allow", "deny"]] = None,
208+
proxy: typing.Optional[typing.Literal['allow', 'deny']] = None,
209209
) -> None:
210210
self.title = title
211211
self.body = body
@@ -288,8 +288,8 @@ def __init__(
288288
self,
289289
headers: typing.Optional[typing.Dict[str, str]] = None,
290290
data: typing.Optional[typing.Dict[str, str]] = None,
291-
notification: typing.Optional["WebpushNotification"] = None,
292-
fcm_options: typing.Optional["WebpushFCMOptions"] = None,
291+
notification: typing.Optional['WebpushNotification'] = None,
292+
fcm_options: typing.Optional['WebpushFCMOptions'] = None,
293293
) -> None:
294294
self.headers = headers
295295
self.data = data
@@ -355,7 +355,7 @@ def __init__(
355355
actions: typing.Optional[typing.List[WebpushNotificationAction]] = None,
356356
badge: typing.Optional[str] = None,
357357
data: typing.Optional[typing.Any] = None,
358-
direction: typing.Optional[typing.Literal["auto", "ltr", "rtl"]] = None,
358+
direction: typing.Optional[typing.Literal['auto', 'ltr', 'rtl']] = None,
359359
image: typing.Optional[str] = None,
360360
language: typing.Optional[str] = None,
361361
renotify: typing.Optional[bool] = None,
@@ -415,8 +415,8 @@ class APNSConfig:
415415
def __init__(
416416
self,
417417
headers: typing.Optional[typing.Dict[str, str]] = None,
418-
payload: typing.Optional["APNSPayload"] = None,
419-
fcm_options: typing.Optional["APNSFCMOptions"] = None,
418+
payload: typing.Optional['APNSPayload'] = None,
419+
fcm_options: typing.Optional['APNSFCMOptions'] = None,
420420
live_activity_token: typing.Optional[str] = None,
421421
) -> None:
422422
self.headers = headers
@@ -434,7 +434,7 @@ class APNSPayload:
434434
(optional).
435435
"""
436436

437-
def __init__(self, aps: "Aps", **kwargs: typing.Any) -> None:
437+
def __init__(self, aps: 'Aps', **kwargs: typing.Any) -> None:
438438
self.aps = aps
439439
self.custom_data = kwargs
440440

@@ -459,9 +459,9 @@ class Aps:
459459

460460
def __init__(
461461
self,
462-
alert: typing.Optional[typing.Union["ApsAlert", str]] = None,
462+
alert: typing.Optional[typing.Union['ApsAlert', str]] = None,
463463
badge: typing.Optional[float] = None, # should it be int?
464-
sound: typing.Optional[typing.Union[str, "CriticalSound"]] = None,
464+
sound: typing.Optional[typing.Union[str, 'CriticalSound']] = None,
465465
content_available: typing.Optional[bool] = None,
466466
category: typing.Optional[str] = None,
467467
thread_id: typing.Optional[str] = None,

0 commit comments

Comments
 (0)