void-packages/srcpkgs/python3-jupyter_server/patches/utcnow-deprecation.patch
2023-10-10 12:29:16 -04:00

39 lines
1.4 KiB
Diff

See: https://github.com/jupyter-server/jupyter_server/issues/1296#issuecomment-1751887150
--- a/jupyter_server/_tz.py
+++ b/jupyter_server/_tz.py
@@ -5,7 +5,7 @@ Just UTC-awareness right now
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
-from datetime import datetime, timedelta, tzinfo
+from datetime import datetime, timedelta, tzinfo, timezone
# constant for zero offset
ZERO = timedelta(0)
@@ -39,6 +39,12 @@ def utc_aware(unaware):
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):
"""Return iso-formatted timestamp
diff --git a/tests/test_gateway.py b/tests/test_gateway.py
index 8f7f8a463..598006e29 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,