File: py3.12-avoid-utcfromtimestamp.patch

package info (click to toggle)
python-passlib 1.7.4-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,920 kB
  • sloc: python: 23,094; makefile: 3
file content (59 lines) | stat: -rw-r--r-- 2,442 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Description: utcfromtimestamp() is deprecated in Python 3.12
Author: Thomas Goirand <zigo@debian.org>
Forwarded: no
Last-Update: 2023-12-23

--- python-passlib-1.7.4.orig/passlib/tests/test_totp.py
+++ python-passlib-1.7.4/passlib/tests/test_totp.py
@@ -62,9 +62,9 @@ def _get_max_time_t():
     while True:
         next_value = value << 1
         try:
-            next_year = datetime.datetime.utcfromtimestamp(next_value-1).year
+            next_year = datetime.datetime.fromtimestamp(next_value-1, datetime.UTC).year
         except (ValueError, OSError, OverflowError):
-            # utcfromtimestamp() may throw any of the following:
+            # fromtimestamp() may throw any of the following:
             #
             # * year out of range for datetime:
             #   py < 3.6 throws ValueError.
@@ -787,7 +787,7 @@ class TotpTest(TestCase):
 
             self.assertEqual(otp.normalize_time(tint), tint)
 
-            dt = datetime.datetime.utcfromtimestamp(time)
+            dt = datetime.datetime.fromtimestamp(time, datetime.UTC)
             self.assertEqual(otp.normalize_time(dt), tint)
 
             orig = TotpFactory.now
@@ -890,7 +890,7 @@ class TotpTest(TestCase):
         self.assertNotEqual(otp.generate(start_time + 30).token, token)
 
         # verify round-trip conversion of datetime
-        dt = datetime.datetime.utcfromtimestamp(time)
+        dt = datetime.datetime.fromtimestamp(time, datetime.UTC)
         self.assertEqual(int(otp.normalize_time(dt)), int(time))
 
         # handle datetime object
@@ -1053,7 +1053,7 @@ class TotpTest(TestCase):
         #-------------------------------
 
         # handle datetimes
-        dt = datetime.datetime.utcfromtimestamp(time)
+        dt = datetime.datetime.fromtimestamp(time, datetime.UTC)
         assertMatches(0, token, dt, window=0)
 
         # reject invalid time
diff --git a/passlib/_setup/stamp.py b/passlib/_setup/stamp.py
index f14c0d4..3f6b92a 100644
--- a/passlib/_setup/stamp.py
+++ b/passlib/_setup/stamp.py
@@ -111,7 +111,7 @@ def append_hg_revision(version):
     except (OSError, subprocess.CalledProcessError):
         # fallback - just use build date
         now = int(os.environ.get('SOURCE_DATE_EPOCH') or time.time())
-        build_date = datetime.datetime.utcfromtimestamp(now)
+        build_date = datetime.datetime.now(datetime.UTC)
         stamp = build_date.strftime("%Y%m%d%H%M%S")
 
     # modify version