class documentation

class Session:

Known subclasses: session3.DictSession.DictSession

Constructor: Session(id)

View In Hierarchy

Holds information about the current session.

The only information that is likely to be useful to applications is the user attribute, which applications can use as they please.[^1]

See Also: [[SessionManager.py]]

Instance attributes:-

  • id : string

    the session ID (generated by SessionManager and used as the value of the session cookie)

  • user : any

    an object to identify the human being on the other end of the line. It's up to you whether to store just a string in user, or some more complex data structure or object.

  • _remote_address : string

    IP address of user owning this session (only set when the session is created)

  • _creation_time : float

  • _access_time : float

    two ways of keeping track of the "age" of the session. Note that __access_time is maintained by the SessionManager that owns this session, using [_set_access_time()](#methods-for-sessionmanager-only).

  • _form_tokens : string

    Added from N.S.'s code --- Outstanding form tokens. This is used as a queue that can grow in size up to MAX_FORM_TOKENS. Tokens are removed when forms are submitted.

Feel free to access id and user directly, but do not modify id. The preferred way to set user is with the set_user() method (which you might want to override for type-checking).

[^1]:Note that this class may be split into a SimpleSession superclass and a Session subclass in the future.

Method __init__ __init__ is called only by SessionManager.SessionManager
Method __repr__ Undocumented
Method __str__ Undocumented
Method create_form_token Create a new form token and add it to a queue of outstanding form tokens for this session. A maximum of MAX_FORM_TOKENS are saved. The new token is returned.
Method dump Undocumented
Method get_access_age Return the number of seconds since session was last accessed.
Method get_access_time Return the time that this session was last accessed (seconds since epoch).
Method get_creation_age _now arg is not strictly necessary, but there for consistency with get_access_age()
Method get_creation_time Return the time that this session was created (seconds since epoch).
Method get_remote_address Return the IP address (dotted-quad string) that made the initial request in this session.
Method get_user Undocumented
Method has_form_token Return True if token is in the queue of outstanding tokens.
Method has_info Return True if this session contains any information that must be saved.
Method remove_form_token Remove token from the queue of outstanding tokens.
Method set_user Undocumented
Method start_request Called near the beginning of each request: after the HTTPRequest object has been built, but before we traverse the URL or call the callable object found by URL traversal.
Constant MAX_FORM_TOKENS Undocumented
Instance Variable id Undocumented
Instance Variable user Undocumented
Method _set_access_time Undocumented
Instance Variable _access_time Undocumented
Instance Variable _creation_time Undocumented
Instance Variable _form_tokens Undocumented
Instance Variable _remote_address Undocumented
def __init__(self, id):
def __repr__(self):

Undocumented

def __str__(self):

Undocumented

def create_form_token(self) -> str:

Create a new form token and add it to a queue of outstanding form tokens for this session. A maximum of MAX_FORM_TOKENS are saved. The new token is returned.

def dump(self, file=None, header=True, deep=True):

Undocumented

def get_access_age(self, _now=None):

Return the number of seconds since session was last accessed.

_now arg is for SessionManager's use

def get_access_time(self):

Return the time that this session was last accessed (seconds since epoch).

def get_creation_age(self, _now=None):

Return the number of seconds since session was created.
_now arg is not strictly necessary, but there for consistency with get_access_age()

def get_creation_time(self):

Return the time that this session was created (seconds since epoch).

def get_remote_address(self):

Return the IP address (dotted-quad string) that made the initial request in this session.

def get_user(self):

Undocumented

def has_form_token(self, token: str) -> bool:

Return True if token is in the queue of outstanding tokens.

def has_info(self) -> bool:

Return True if this session contains any information that must be saved.

def remove_form_token(self, token: str):

Remove token from the queue of outstanding tokens.

def set_user(self, user):

Undocumented

def start_request(self):

Called near the beginning of each request: after the HTTPRequest object has been built, but before we traverse the URL or call the callable object found by URL traversal.

MAX_FORM_TOKENS: int =

Undocumented

Value
32
id =

Undocumented

user =

Undocumented

def _set_access_time(self, resolution):

Undocumented

_access_time =

Undocumented

_creation_time =

Undocumented

_form_tokens: list =

Undocumented

_remote_address =

Undocumented