From 798aa63e231af28ed8fc3b1619812f2569f6d456 Mon Sep 17 00:00:00 2001 From: eddiedigits Date: Wed, 6 Nov 2024 20:38:11 +0100 Subject: [PATCH] replaced deprecated datetime.utcnow() with datetime.now() --- docs/chapter-06.rst | 2 +- py4web/core.py | 4 ++-- py4web/utils/auth.py | 6 +++--- py4web/utils/dbstore.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/chapter-06.rst b/docs/chapter-06.rst index dc1b0dd08..a46278d74 100644 --- a/docs/chapter-06.rst +++ b/docs/chapter-06.rst @@ -711,7 +711,7 @@ it doesn't exist: @action.uses(db) def index(): client_ip = request.environ.get('REMOTE_ADDR') - db.visit_log.insert(client_ip=client_ip, timestamp=datetime.utcnow()) + db.visit_log.insert(client_ip=client_ip, timestamp=datetime.now()) return "Your visit was stored in database" Notice that the database fixture defines (creates/re-creates) tables diff --git a/py4web/core.py b/py4web/core.py index da825f297..1115d8ade 100644 --- a/py4web/core.py +++ b/py4web/core.py @@ -1168,7 +1168,7 @@ def get_error_snapshot(depth=5): etype = etype.__name__ data = {} - data["timestamp"] = datetime.datetime.utcnow().isoformat().replace("T", " ") + data["timestamp"] = datetime.datetime.now().isoformat().replace("T", " ") data["python_version"] = sys.version platform_keys = [ "machine", @@ -1248,7 +1248,7 @@ def log(self, app_name, error_snapshot): app_name=app_name, method=request.method, path=request.path, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.datetime.now(), client_ip=request.environ.get("REMOTE_ADDR"), error=error_snapshot["exception_value"], snapshot=error_snapshot, diff --git a/py4web/utils/auth.py b/py4web/utils/auth.py index e8b501ebd..4f7a1654a 100644 --- a/py4web/utils/auth.py +++ b/py4web/utils/auth.py @@ -126,7 +126,7 @@ def on_request(self, context): # record the time of the latest activity for logged in user (with throttling) if not activity or time_now - activity > 6: self.auth.session["recent_activity"] = time_now - self.auth.session["recent_timestamp"] = datetime.datetime.utcnow().isoformat() + self.auth.session["recent_timestamp"] = datetime.datetime.now().isoformat() if callable(self.condition) and not self.condition(user): self.abort_or_redirect("not-authorized", "User not authorized") @@ -424,7 +424,7 @@ def define_tables(self): @property def signature(self): """Returns a list of fields for a table signature""" - now = lambda: datetime.datetime.utcnow() + now = lambda: datetime.datetime.now() user = lambda s=self: s.user_id fields = [ Field( @@ -787,7 +787,7 @@ def change_password( past_passwords_hash=past_pwds ) num = db(db.auth_user.id == user.get("id")).update( - password=new_pwd, last_password_change=datetime.datetime.utcnow() + password=new_pwd, last_password_change=datetime.datetime.now() ) return {"updated": num} diff --git a/py4web/utils/dbstore.py b/py4web/utils/dbstore.py index 292a9b7e4..9357dae43 100644 --- a/py4web/utils/dbstore.py +++ b/py4web/utils/dbstore.py @@ -19,7 +19,7 @@ def __init__(self, db, name="py4web_session"): self.table = db[name] def get(self, key): - db, table, now = self.db, self.table, datetime.utcnow() + db, table, now = self.db, self.table, datetime.now() row = db(table.rkey == key).select().first() if not row: return None @@ -28,7 +28,7 @@ def get(self, key): return row.rvalue def set(self, key, value, expiration=None): - db, table, now = self.db, self.table, datetime.utcnow() + db, table, now = self.db, self.table, datetime.now() db(table.expires_on < now).delete() row = db(table.rkey == key).select().first() expires_on = (