Skip to content

Commit

Permalink
Consistent expiration naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Lxstr committed Jan 15, 2024
1 parent 96408be commit 6833806
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/flask_session/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def save_session(self, app, session, response):
return

# Get the new expiration time for the session
expires = self.get_expiration_time(app, session)
expiration_datetime = self.get_expiration_time(app, session)

# Serialize the session data
serialized_session_data = self.serializer.dumps(dict(session))
Expand All @@ -204,7 +204,7 @@ def save_session(self, app, session, response):
)

# Set the browser cookie
self.set_cookie_to_response(app, session, response, expires)
self.set_cookie_to_response(app, session, response, expiration_datetime)


class MemcachedSessionInterface(ServerSideSessionInterface):
Expand Down Expand Up @@ -295,7 +295,7 @@ def save_session(self, app, session, response):
return

# Get the new expiration time for the session
expires = self.get_expiration_time(app, session)
expiration_datetime = self.get_expiration_time(app, session)

# Serialize the session data
serialized_session_data = self.serializer.dumps(dict(session))
Expand All @@ -308,7 +308,7 @@ def save_session(self, app, session, response):
)

# Set the browser cookie
self.set_cookie_to_response(app, session, response, expires)
self.set_cookie_to_response(app, session, response, expiration_datetime)


class FileSystemSessionInterface(ServerSideSessionInterface):
Expand Down Expand Up @@ -378,7 +378,7 @@ def save_session(self, app, session, response):
return

# Get the new expiration time for the session
expires = self.get_expiration_time(app, session)
expiration_datetime = self.get_expiration_time(app, session)

# Serialize the session data (or just cast into dictionary in this case)
session_data = dict(session)
Expand All @@ -391,7 +391,7 @@ def save_session(self, app, session, response):
)

# Set the browser cookie
self.set_cookie_to_response(app, session, response, expires)
self.set_cookie_to_response(app, session, response, expiration_datetime)


class MongoDBSessionInterface(ServerSideSessionInterface):
Expand Down Expand Up @@ -490,7 +490,7 @@ def save_session(self, app, session, response):
return

# Get the new expiration time for the session
expires = self.get_expiration_time(app, session)
expiration_datetime = self.get_expiration_time(app, session)

# Serialize the session data
serialized_session_data = self.serializer.dumps(dict(session))
Expand All @@ -502,7 +502,7 @@ def save_session(self, app, session, response):
{
"id": prefixed_session_id,
"val": serialized_session_data,
"expiration": expires,
"expiration": expiration_datetime,
},
True,
)
Expand All @@ -513,14 +513,14 @@ def save_session(self, app, session, response):
"$set": {
"id": prefixed_session_id,
"val": serialized_session_data,
"expiration": expires,
"expiration": expiration_datetime,
}
},
True,
)

# Set the browser cookie
self.set_cookie_to_response(app, session, response, expires)
self.set_cookie_to_response(app, session, response, expiration_datetime)


class SqlAlchemySessionInterface(ServerSideSessionInterface):
Expand Down Expand Up @@ -610,8 +610,8 @@ def fetch_session(self, sid):

# If the expiration time is less than or equal to the current time (expired), delete the document
if record is not None:
expiration = record.get("expiration")
if expiration is None or expiration <= datetime.utcnow():
expiration_datetime = record.expiry
if expiration_datetime is None or expiration_datetime <= datetime.utcnow():
self.db.session.delete(record)
self.db.session.commit()
record = None
Expand Down Expand Up @@ -653,23 +653,23 @@ def save_session(self, app, session, response):
serialized_session_data = self.serializer.dumps(dict(session))

# Get the new expiration time for the session
expires = self.get_expiration_time(app, session)
expiration_datetime = self.get_expiration_time(app, session)

# Update existing or create new session in the database
record = self.sql_session_model.query.filter_by(
session_id=prefixed_session_id
).first()
if record:
record.data = serialized_session_data
record.expiry = expires
record.expiry = expiration_datetime
else:
record = self.sql_session_model(
session_id=prefixed_session_id,
data=serialized_session_data,
expiry=expires,
expiry=expiration_datetime,
)
self.db.session.add(record)
self.db.session.commit()

# Set the browser cookie
self.set_cookie_to_response(app, session, response, expires)
self.set_cookie_to_response(app, session, response, expiration_datetime)

0 comments on commit 6833806

Please sign in to comment.