Skip to content

Commit

Permalink
make managed session more like a real session
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Feb 25, 2018
1 parent 4d1c3cc commit fdf8edb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion flask_socketio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import socketio
import flask
from flask import _request_ctx_stack, json as flask_json
from flask.sessions import SessionMixin
from werkzeug.debug import DebuggedApplication
from werkzeug.serving import run_with_reloader

Expand All @@ -42,6 +43,13 @@ def __call__(self, environ, start_response):
start_response)


class _ManagedSession(SessionMixin, dict):
"""This class is used for user sessions that are managed by
Flask-SocketIO. It is simple dict, expanded with the Flask session
attributes."""
pass


class SocketIO(object):
"""Create a Flask-SocketIO server.
Expand Down Expand Up @@ -606,7 +614,7 @@ def _handle_event(self, handler, message, namespace, sid, *args):
# created as a copy of the regular user session
if 'saved_session' not in self.server.environ[sid]:
self.server.environ[sid]['saved_session'] = \
dict(flask.session)
_ManagedSession(flask.session)
session_obj = self.server.environ[sid]['saved_session']
else:
# let Flask handle the user session
Expand Down

0 comments on commit fdf8edb

Please sign in to comment.