Skip to content

Commit

Permalink
Addressed additional problems with multi-application support
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Oct 16, 2015
1 parent 725c4bf commit 37316d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions flask_socketio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


class _SocketIOMiddleware(socketio.Middleware):
"""This WSGI middleware simply pushes a Flask application context before
before executing the request.
"""This WSGI middleware simply exposes the Flask application in the WSGI
environment before executing the request.
"""
def __init__(self, socketio_app, flask_app, socketio_path='socket.io'):
self.flask_app = flask_app
Expand All @@ -19,9 +19,9 @@ def __init__(self, socketio_app, flask_app, socketio_path='socket.io'):
socketio_path)

def __call__(self, environ, start_response):
with self.flask_app.app_context():
return super(_SocketIOMiddleware, self).__call__(environ,
start_response)
environ['flask.app'] = self.flask_app
return super(_SocketIOMiddleware, self).__call__(environ,
start_response)


class SocketIO(object):
Expand Down Expand Up @@ -127,8 +127,8 @@ def handle_my_custom_event(json):

def decorator(handler):
def _handler(sid, *args):
with flask.current_app.request_context(
self.server.environ[sid]):
app = self.server.environ[sid]['flask.app']
with app.request_context(self.server.environ[sid]):
if 'saved_session' in self.server.environ[sid]:
self._copy_session(
self.server.environ[sid]['saved_session'],
Expand Down
4 changes: 2 additions & 2 deletions flask_socketio/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def _mock_send_packet(sid, pkt):
def connect(self, namespace=None):
"""Connect the client."""
environ = EnvironBuilder('/socket.io').get_environ()
with self.app.app_context():
self.socketio.server._handle_eio_connect(self.sid, environ)
environ['flask.app'] = self.app
self.socketio.server._handle_eio_connect(self.sid, environ)
if namespace is not None and namespace != '/':
pkt = packet.Packet(packet.CONNECT, namespace=namespace)
with self.app.app_context():
Expand Down

0 comments on commit 37316d7

Please sign in to comment.