MCPcopy
hub / github.com/django/django / get_expiry_age

Method get_expiry_age

django/contrib/sessions/backends/base.py:273–298  ·  view source on GitHub ↗

Get the number of seconds until the session expires. Optionally, this function accepts `modification` and `expiry` keyword arguments specifying the modification and expiry of the session.

(self, **kwargs)

Source from the content-addressed store, hash-verified

271 return settings.SESSION_COOKIE_AGE
272
273 def get_expiry_age(self, **kwargs):
274 """Get the number of seconds until the session expires.
275
276 Optionally, this function accepts `modification` and `expiry` keyword
277 arguments specifying the modification and expiry of the session.
278 """
279 try:
280 modification = kwargs["modification"]
281 except KeyError:
282 modification = timezone.now()
283 # Make the difference between "expiry=None passed in kwargs" and
284 # "expiry not passed in kwargs", in order to guarantee not to trigger
285 # self.load() when expiry is provided.
286 try:
287 expiry = kwargs["expiry"]
288 except KeyError:
289 expiry = self.get("_session_expiry")
290
291 if not expiry: # Checks both None and 0 cases
292 return self.get_session_cookie_age()
293 if not isinstance(expiry, (datetime, str)):
294 return expiry
295 if isinstance(expiry, str):
296 expiry = datetime.fromisoformat(expiry)
297 delta = expiry - modification
298 return delta.days * 86400 + delta.seconds
299
300 async def aget_expiry_age(self, **kwargs):
301 try:

Callers 12

process_responseMethod · 0.80
loadMethod · 0.80
saveMethod · 0.80
saveMethod · 0.80
loadMethod · 0.80
test_default_expiryMethod · 0.80
test_default_expiryMethod · 0.80

Calls 3

getMethod · 0.95
nowMethod · 0.45