Skip to content

Commit

Permalink
remove obsolete Python 2.x style constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Dec 12, 2024
1 parent eeb3c43 commit 6a6734f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion example/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
// These accept data from the user and send it to the server in a
// variety of ways
$('form#emit').submit(function(event) {
socket.emit('my_event_foo', {data: $('#emit_data').val()});
socket.emit('my_event', {data: $('#emit_data').val()});
return false;
});
$('form#broadcast').submit(function(event) {
Expand Down
14 changes: 6 additions & 8 deletions src/flask_socketio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ class _SocketIOMiddleware(socketio.WSGIApp):
"""
def __init__(self, socketio_app, flask_app, socketio_path='socket.io'):
self.flask_app = flask_app
super(_SocketIOMiddleware, self).__init__(socketio_app,
flask_app.wsgi_app,
socketio_path=socketio_path)
super().__init__(socketio_app, flask_app.wsgi_app,
socketio_path=socketio_path)

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


class _ManagedSession(dict, SessionMixin):
Expand All @@ -51,7 +49,7 @@ class _ManagedSession(dict, SessionMixin):
pass


class SocketIO(object):
class SocketIO:
"""Create a Flask-SocketIO server.
:param app: The flask application instance. If the application instance
Expand Down Expand Up @@ -204,7 +202,7 @@ def init_app(self, app, **kwargs):
if url:
if url.startswith(('redis://', "rediss://")):
queue_class = socketio.RedisManager
elif url.startswith(('kafka://')):
elif url.startswith('kafka://'):
queue_class = socketio.KafkaManager
elif url.startswith('zmq'):
queue_class = socketio.ZmqManager
Expand All @@ -220,7 +218,7 @@ def init_app(self, app, **kwargs):
# changes when it is invoked inside or outside the app context
# so here to prevent any ambiguities we replace it with wrappers
# that ensure that the app context is always present
class FlaskSafeJSON(object):
class FlaskSafeJSON:
@staticmethod
def dumps(*args, **kwargs):
with app.app_context():
Expand Down
2 changes: 1 addition & 1 deletion src/flask_socketio/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Namespace(_Namespace):
def __init__(self, namespace=None):
super(Namespace, self).__init__(namespace)
super().__init__(namespace)
self.socketio = None

def _set_socketio(self, socketio):
Expand Down
2 changes: 1 addition & 1 deletion src/flask_socketio/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from werkzeug.test import EnvironBuilder


class SocketIOTestClient(object):
class SocketIOTestClient:
"""
This class is useful for testing a Flask-SocketIO server. It works in a
similar way to the Flask Test Client, but adapted to the Socket.IO server.
Expand Down
2 changes: 1 addition & 1 deletion test_socketio.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def test_emit(self):
def test_emit_binary(self):
client = socketio.test_client(app, auth={'foo': 'bar'})
client.get_received()
client.emit('my custom event', {u'a': b'\x01\x02\x03'})
client.emit('my custom event', {'a': b'\x01\x02\x03'})
received = client.get_received()
self.assertEqual(len(received), 1)
self.assertEqual(len(received[0]['args']), 1)
Expand Down

0 comments on commit 6a6734f

Please sign in to comment.