From 834816132e8ab04a3cff1afec410e63cb167d605 Mon Sep 17 00:00:00 2001 From: Guri-X Date: Sun, 21 Apr 2024 16:00:52 +0530 Subject: [PATCH 1/3] Replaced the 'datetime.utcnow()' method with 'datetime.now(timezone.utc)' --- src/betamax/adapter.py | 4 ++-- src/betamax/util.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/betamax/adapter.py b/src/betamax/adapter.py index 8e8a0d2..2165484 100644 --- a/src/betamax/adapter.py +++ b/src/betamax/adapter.py @@ -9,7 +9,7 @@ from . import cassette from .exceptions import BetamaxError -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from requests.adapters import BaseAdapter, HTTPAdapter _SENTINEL = object() @@ -102,7 +102,7 @@ def load_cassette(self, cassette_name, serialize, options): if self.options.get('re_record_interval'): re_record_interval = timedelta(self.options['re_record_interval']) - now = datetime.utcnow() + now = datetime.now(timezone.utc) if re_record_interval < (now - self.cassette.earliest_recorded_date): self.cassette.clear() diff --git a/src/betamax/util.py b/src/betamax/util.py index 3090acc..fab092b 100644 --- a/src/betamax/util.py +++ b/src/betamax/util.py @@ -1,5 +1,5 @@ from .mock_response import MockHTTPResponse -from datetime import datetime +from datetime import datetime, timezone from requests.models import PreparedRequest, Response from requests.packages.urllib3 import HTTPResponse from requests.structures import CaseInsensitiveDict @@ -163,7 +163,7 @@ def add_urllib3_response(serialized, response, headers): def timestamp(): - stamp = datetime.utcnow().isoformat() + stamp = datetime.now(timezone.utc).isoformat().split("+")[0] try: i = stamp.rindex('.') except ValueError: From dd5396a28dd2fc0e6850398f03d85138abf10d09 Mon Sep 17 00:00:00 2001 From: Guri-X Date: Sun, 5 May 2024 12:35:32 +0530 Subject: [PATCH 2/3] Handled 'TypeError: can't subtract offset-naive and offset-aware datetimes' in the BetamaxAdapter class --- src/betamax/adapter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/betamax/adapter.py b/src/betamax/adapter.py index 2165484..2b2e5cb 100644 --- a/src/betamax/adapter.py +++ b/src/betamax/adapter.py @@ -102,7 +102,7 @@ def load_cassette(self, cassette_name, serialize, options): if self.options.get('re_record_interval'): re_record_interval = timedelta(self.options['re_record_interval']) - now = datetime.now(timezone.utc) + now = datetime.now(timezone.utc).replace(tzinfo=None) if re_record_interval < (now - self.cassette.earliest_recorded_date): self.cassette.clear() From 38fcd930bfed116b8510fb3234e4b43e6db6571e Mon Sep 17 00:00:00 2001 From: Ian Stapleton Cordasco Date: Mon, 6 May 2024 06:44:17 -0500 Subject: [PATCH 3/3] Use strftime to create timestamp --- src/betamax/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/betamax/util.py b/src/betamax/util.py index fab092b..5355294 100644 --- a/src/betamax/util.py +++ b/src/betamax/util.py @@ -163,7 +163,7 @@ def add_urllib3_response(serialized, response, headers): def timestamp(): - stamp = datetime.now(timezone.utc).isoformat().split("+")[0] + stamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S") try: i = stamp.rindex('.') except ValueError: