Fixed linter check for #2506

This commit is contained in:
Andrew-Chen-Wang 2020-03-24 16:12:47 -04:00
parent c4eaf68982
commit 910ed86d11
2 changed files with 9 additions and 13 deletions

View File

@ -11,6 +11,7 @@ import sys
from pathlib import Path from pathlib import Path
from django.core.asgi import get_asgi_application from django.core.asgi import get_asgi_application
from .websocket import websocket_application from .websocket import websocket_application
# This allows easy placement of apps within the interior # This allows easy placement of apps within the interior
@ -33,9 +34,9 @@ django_application = get_asgi_application()
async def application(scope, receive, send): async def application(scope, receive, send):
if scope['type'] == 'http': if scope["type"] == "http":
await django_application(scope, receive, send) await django_application(scope, receive, send)
elif scope['type'] == 'websocket': elif scope["type"] == "websocket":
await websocket_application(scope, receive, send) await websocket_application(scope, receive, send)
else: else:
raise NotImplementedError(f"Unknown scope type {scope['type']}") raise NotImplementedError(f"Unknown scope type {scope['type']}")

View File

@ -2,17 +2,12 @@ async def websocket_application(scope, receive, send):
while True: while True:
event = await receive() event = await receive()
if event['type'] == 'websocket.connect': if event["type"] == "websocket.connect":
await send({ await send({"type": "websocket.accept"})
'type': 'websocket.accept'
})
if event['type'] == 'websocket.disconnect': if event["type"] == "websocket.disconnect":
break break
if event['type'] == 'websocket.receive': if event["type"] == "websocket.receive":
if event['text'] == 'ping': if event["text"] == "ping":
await send({ await send({"type": "websocket.send", "text": "pong!"})
'type': 'websocket.send',
'text': 'pong!'
})