void-packages/srcpkgs/python3-jupyter_server/patches/utcnow-deprecation.patch
2023-11-01 22:25:20 -04:00

47 lines
1.7 KiB
Diff

commit 13def167faf8898b2e19fc04f24c0ff6f6cc35fa
Author: Gonzalo Tornaría <tornaria@cmat.edu.uy>
Date: Mon Oct 16 10:38:36 2023 -0300
utcnow deprecation
See: https://github.com/jupyter-server/jupyter_server/issues/1296#issuecomment-1751887150
diff --git a/jupyter_server/_tz.py b/jupyter_server/_tz.py
index 24847b430..ea3e65fe2 100644
--- a/jupyter_server/_tz.py
+++ b/jupyter_server/_tz.py
@@ -7,7 +7,7 @@ Just UTC-awareness right now
# Distributed under the terms of the Modified BSD License.
from __future__ import annotations
-from datetime import datetime, timedelta, tzinfo
+from datetime import datetime, timedelta, tzinfo, timezone
from typing import Callable
# constant for zero offset
@@ -42,6 +42,12 @@ def utc_aware(unaware: Callable[..., datetime]) -> Callable[..., datetime]:
utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
utcnow = utc_aware(datetime.utcnow)
+def utcnow() -> datetime:
+ """ Return timezone-aware UTC timestamp"""
+ return datetime.now(timezone.utc)
+
+def utcfromtimestamp(timestamp):
+ return datetime.fromtimestamp(timestamp, timezone.utc)
def isoformat(dt: datetime) -> str:
"""Return iso-formatted timestamp
diff --git a/tests/test_gateway.py b/tests/test_gateway.py
index 37ce8b03e..e1ea0869e 100644
--- a/tests/test_gateway.py
+++ b/tests/test_gateway.py
@@ -78,7 +78,7 @@ omitted_kernels: Dict[str, bool] = {}
def generate_model(name):
"""Generate a mocked kernel model. Caller is responsible for adding model to running_kernels dictionary."""
- dt = datetime.utcnow().isoformat() + "Z" # noqa
+ dt = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z") # noqa
kernel_id = str(uuid.uuid4())
model = {
"id": kernel_id,