def test_mixed_unicode_bytes(self): """ Tests that having the message key be bytes and pattern unicode (or vice-versa) still works. """ # Unicode patterns, byte message router = Router([ route("websocket.connect", consumer_1, path="^/foo/"), include("channels.tests.test_routing.chatroom_routing", path="^/ws/v(?P<version>[0-9]+)"), ]) self.assertRoute( router, channel="websocket.connect", content={"path": b"/boom/"}, consumer=None, ) self.assertRoute( router, channel="websocket.connect", content={"path": b"/foo/"}, consumer=consumer_1, ) self.assertRoute( router, channel="websocket.connect", content={"path": b"/ws/v2/chat/django/"}, consumer=consumer_2, kwargs={"version": "2", "room": "django"}, ) # Byte patterns, unicode message router = Router([ route("websocket.connect", consumer_1, path=b"^/foo/"), include("channels.tests.test_routing.chatroom_routing", path=b"^/ws/v(?P<version>[0-9]+)"), ]) self.assertRoute( router, channel="websocket.connect", content={"path": "/boom/"}, consumer=None, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/foo/"}, consumer=consumer_1, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/ws/v2/chat/django/"}, consumer=consumer_2, kwargs={"version": "2", "room": "django"}, )
def test_include_prefix(self): """ Tests inclusion with a prefix """ router = Router([ include("channels.tests.test_routing.chatroom_routing", path="^/ws/v(?P<version>[0-9]+)"), ]) self.assertRoute( router, channel="websocket.connect", content={"path": "/boom/"}, consumer=None, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/chat/django/"}, consumer=None, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/ws/v2/chat/django/"}, consumer=consumer_2, kwargs={ "version": "2", "room": "django" }, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/ws/v1/mentions/"}, consumer=consumer_3, kwargs={"version": "1"}, ) # Check it works without the ^s too. router = Router([ include("channels.tests.test_routing.chatroom_routing_nolinestart", path="/ws/v(?P<version>[0-9]+)"), ]) self.assertRoute( router, channel="websocket.connect", content={"path": "/ws/v2/chat/django/"}, consumer=consumer_2, kwargs={ "version": "2", "room": "django" }, )
def test_bad_include_prefix(self): """ Tests both failure cases of prefixes for includes - the include not starting with ^, and the included filter not starting with ^. """ with self.assertRaises(ValueError): Router([ include("channels.tests.test_routing.chatroom_routing", path="foobar"), ]) with self.assertRaises(ValueError): Router([ include("channels.tests.test_routing.chatroom_routing_noprefix", path="^/foobar/"), ])
def test_include(self): """ Tests inclusion without a prefix """ router = Router([ include("channels.tests.test_routing.chatroom_routing"), ]) self.assertRoute( router, channel="websocket.connect", content={"path": "/boom/"}, consumer=None, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/chat/django/"}, consumer=consumer_2, kwargs={"room": "django"}, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/mentions/"}, consumer=consumer_3, kwargs={}, )
def test_include_prefix(self): """ Tests inclusion with a prefix """ router = Router([ include("channels.tests.test_routing.chatroom_routing", path="^/ws/v(?P<version>[0-9]+)"), ]) self.assertRoute( router, channel="websocket.connect", content={"path": "/boom/"}, consumer=None, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/chat/django/"}, consumer=None, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/ws/v2/chat/django/"}, consumer=consumer_2, kwargs={"version": "2", "room": "django"}, ) self.assertRoute( router, channel="websocket.connect", content={"path": "/ws/v1/mentions/"}, consumer=consumer_3, kwargs={"version": "1"}, )
def test_route_class(self): """ Tests route_class with/without prefix """ router = Router([ include("channels.tests.test_routing.class_routing"), ]) self.assertRoute( router, channel="websocket.connect", content={"path": "/foobar/"}, consumer=None, ) self.assertRoute( router, channel="test.channel", content={"path": "/foobar/"}, consumer=TestClassConsumer, ) self.assertRoute( router, channel="test.channel", content={"path": "/"}, consumer=None, )
# -*- coding: utf-8 -*- from __future__ import absolute_import, print_function, unicode_literals from channels.routing import include from documents.routing import channel_routing as documents_routing # equivalent to my_project.urls # tipically used to include application routing channel_routing = [ include(documents_routing, path=r'^/status'), ]
from channels.routing import route, include from trams import consumers as trams_consumers trams_channels = [ route('websocket.connect', trams_consumers.ws_add), route('websocket.disconnect', trams_consumers.ws_disconnect), ] channel_routing = [ include(trams_channels, path=r'^/trams/$'), ]
from channels.routing import route, include from chat_engine.routing import routing as chat_routing routing = [ include(chat_routing, path=r"^/chat"), ]
from channels.routing import route, include from chat.consumers import ws_message, ws_connect ws_routing = [ route("websocket.receive", ws_message), route("websocket.connect", ws_connect), ] channel_routing = [ include(ws_routing, path=r"^/chat"), ]
from channels.routing import route, include from chat.routing import channel_routing as chat_routing from notices.routing import channel_routing as notices_routing main_routing = [ include(chat_routing, path=r'^/chat'), include(notices_routing, path=r'^/notices') ] channel_routing = [include(main_routing, path=r'^/ws')]
from channels.routing import include from .consumers import * channel_routing = [ include([ TablingConsumer.as_route(path=r'^building/(?P<building>\d+)/ws/$'), include([ ShowConsumer.as_route(path=r'^auditions/ws/$'), CallbackConsumer.as_route(path=r'^callbacks/ws/$'), CastListConsumer.as_route(path=r'^cast/ws/$'), ], path="^show/(?P<show>\d+)/"), ], path="^staff/"), ]
from channels.routing import route from .consumers import ws_message, ws_connect, ws_disconnect from otree.channels.routing import channel_routing from channels.routing import include, route_class ebay_routing = [route("websocket.connect", ws_connect, path=r'^/(?P<group_name>\w+)$'), route("websocket.receive", ws_message, path=r'^/(?P<group_name>\w+)$'), route("websocket.disconnect", ws_disconnect, path=r'^/(?P<group_name>\w+)$'), ] channel_routing += [ include(ebay_routing, path=r"^/ebay"), ]
route("websocket.connect", ws_connect), # Called when WebSockets disconnect route("websocket.disconnect", ws_disconnect), # Called when WebSockets get sent a data frame route("websocket.receive", ws_receive), ] # You can have as many lists here as you like, and choose any name. # Just refer to the individual names in the include() function. custom_routing = [ # Handling different chat commands (websocket.receive is decoded and put # onto this channel) - routed on the "command" attribute of the decoded # message. # route("notify.receive", set_notification_as_seen, command="^seen", ), route("notify.receive", user_connected, command="^user_connect", ), ] channel_routing = [ # Include sub-routing from an app. include(websocket_routing, path=r"^/websocket"), # Custom handler for message sending (see Room.send_message). # Can't go in the include above as it's not got a `path` attribute to match on. include(custom_routing), # A default "http.request" route is always inserted by Django at the end of the routing list # that routes all unmatched HTTP requests to the Django view system. If you want lower-level # HTTP handling - e.g. long-polling - you can do it here and route by path, and let the rest # fall through to normal views. ]
# In routing.py from channels.routing import route, include from dcp.consumers import * chat_routing = [ route("websocket.receive", ws_message), route("websocket.connect", ws_connect), route("websocket.disconnect", ws_disconnect) ] notifications_routing = [ route("websocket.connect",notifier_ws_connect), route("websocket.disconnect",notifier_ws_disconnect), route("websocket.receive",notifier_ws_message) ] notifications_count_routing = [ # Kein Receive! route("websocket.connect",ws_notifier_count_connect), route("websocket.disconnect",ws_notifier_count_disconnect) ] channel_routing = [ include(chat_routing, path=r"^/chat/(?P<userid>\d+)/$"), route("chat-messages",msg_consumer), include(notifications_routing,path=r"^/notifications/$"), route("notification-messages",notify_msg_consumer), include(notifications_count_routing,path="^/notifications_count/$"), #include(notify_all_routing,path=r"^/notify_all/$"), #route("notificaty-all",public_notifier_msg_consumer) ]
# -*- coding:utf-8 -*- from channels.routing import route, include from ssh_demo.consumers import ws_add, ws_message, ws_disconnect channel_routing = [ route("websocket.connect", ws_add, path=r"^/(?P<ip>d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/$"), route("websocket.receive", ws_message), route("websocket.disconnect", ws_disconnect), ] routing = [ # You can use a string import path as the first argument as well. include(channel_routing, path=r"^/channel") ] # channel_routing = [ # route("websocket.connect", ws_add), # route("websocket.receive", ws_message), # route("websocket.disconnect", ws_disconnect), # ]
from channels.routing import route, include from stratus import routing as stratus_routing channel_routing = [ include(stratus_routing.channel_routing) ]
from channels.staticfiles import StaticFilesConsumer from channels.routing import route, include from .consumers import ( ws_connect, ws_message, ws_disconnect, ) http_routing = [ route("http.request", StaticFilesConsumer()), ] chat_routing = [ route("websocket.connect", ws_connect), route("websocket.receive", ws_message), route("websocket.disconnect", ws_disconnect), ] channel_routing = [ include(chat_routing), include(http_routing), ]
# -*- coding: utf-8 -*- from channels.routing import include from catmaid.routing import channel_routing as catmaid_routes # Link connsumer functions to websockets. channel_routing = [ include(catmaid_routes, path='^/channels') ]
from openslides.utils.autoupdate import ( send_data_projector, send_data_site, ws_add_projector, ws_add_site, ws_disconnect_projector, ws_disconnect_site, ws_receive_projector, ws_receive_site, ) projector_routing = [ route("websocket.connect", ws_add_projector), route("websocket.disconnect", ws_disconnect_projector), route("websocket.receive", ws_receive_projector), ] site_routing = [ route("websocket.connect", ws_add_site), route("websocket.disconnect", ws_disconnect_site), route("websocket.receive", ws_receive_site), ] channel_routing = [ include(projector_routing, path=r'^/ws/projector/(?P<projector_id>\d+)/$'), include(site_routing, path=r'^/ws/site/$'), route("autoupdate.send_data_projector", send_data_projector), route("autoupdate.send_data_site", send_data_site), ]
from channels.routing import include channel_routing = [include('klasstool.courses.routing.channel_routing')]
from channels.routing import route, include from account import consumers, views websocket_routing = [ route("websocket.receive", consumers.ws_message), route("websocket.connect", consumers.ws_connect), route("websocket.disconnect", consumers.ws_disconnect), ] routing = [ include(websocket_routing), route("http.request", consumers.http_consumer), # route("http.request", views.visit_register, path=r'^register/$'), # route("http.request", views.do_register, path=r'^register/register.do'), # route("http.request", views.visit_login, path=r'^login/$'), # route("http.request", views.do_login, path=r'^login/login.do'), ]
#!/usr/bin/env python # encoding: utf-8 from channels.routing import route, include from honeypot.routing import channel_routing as honeypot channel_routing = [include(honeypot, path="/honeypot")]
from channels.routing import route, include from speakifyit.chats.consumers import chat_connect, chat_message, chat_disconnect, chat_join, chat_leave, chat_send, chat_contact, chat_edit websocket_chat_routing = [ route("websocket.connect", chat_connect, ), route("websocket.receive", chat_message, ), route("websocket.disconnect", chat_disconnect, ), ] chat_routing = [ # Handling different chat commands (websocket.receive is decoded and put # onto this channel) - routed on the "command" attribute of the decoded # message. route("chat.receive", chat_join, command="^join$"), route("chat.receive", chat_leave, command="^leave$"), route("chat.receive", chat_send, command="^send$"), route("chat.receive", chat_contact, command="^contact$"), route("chat.receive", chat_edit, command="^edit$"), ] channel_routing = [ include(websocket_chat_routing), include(chat_routing), ]
from channels.routing import route, include channel_routing = [ include('cq.routing.channel_routing') ]
from channels.routing import route, include # The channel routing defines what channels get handled by what consumers, # including optional matching on message attributes. In this example, we route # all WebSocket connections to the class-based BindingConsumer (the consumer # class itself specifies what channels it wants to consume) channel_routing = [ #route_class(Demultiplexer, path='^/stream/?$'), include("TEST.routing.websocket_routing"), ]
route("websocket.receive", dir_ws_message, path=dir_auction_path), route("websocket.disconnect", dir_ws_disconnect, path=dir_auction_path), ] dir_workpage_routing = [ route("websocket.connect", dir_work_connect, path=work_path), route("websocket.receive", dir_work_message, path=work_path), route("websocket.disconnect", dir_work_disconnect, path=work_path), ] wageauction_routing = [ route("websocket.connect", ws_connect, path=auction_path), route("websocket.receive", ws_message, path=auction_path), route("websocket.disconnect", ws_disconnect, path=auction_path), ] workpage_routing = [ route("websocket.connect", work_connect, path=work_path), route("websocket.receive", work_message, path=work_path), route("websocket.disconnect", work_disconnect, path=work_path), ] channel_routing += [ include(tut_answer_routing, path=r"^/questionnaire"), include(tut_workpage_routing, path=r"^/tutworkpage"), include(directauction_routing, path=r"^/directauction"), include(dir_workpage_routing, path=r"^/dirworkpage"), include(wageauction_routing, path=r"^/wageauction"), include(workpage_routing, path=r"^/workpage"), ]
from channels.routing import route, include from mtgapp.consumers import game_connect, game_disconnect game_routing = [ route("websocket.connect", game_connect, path=r'^/(?P<game_id>[a-zA-Z0-9_]+)/$'), route("websocket.disconnect", game_disconnect), route('websocket.receive', 'mtgapp.consumers.ws_consumer'), ] routing = [ include(game_routing, path=r'^/game'), ]
from channels.routing import route from .consumers import ws_message, ws_connect, ws_disconnect from otree.channels.routing import channel_routing from channels.routing import include ending = r'^/(?P<participant_code>\w+)/(?P<player_pk>\w+)$' hangman_routing = [ route("websocket.connect", ws_connect, path=ending), route("websocket.receive", ws_message, path=ending), route("websocket.disconnect", ws_disconnect, path=ending), ] channel_routing += [ include(hangman_routing, path=r"^/hangman"), ]
from channels.routing import route, include from refer.consumers import ws_message, ws_connect ws_routing = [ route("websocket.receive", ws_message), route("websocket.connect", ws_connect), ] channel_routing = [ include(ws_routing, path=r"^/chat"), ]
from channels.routing import route from .consumers import ws_message, ws_connect, ws_disconnect, wait_page_connect, wait_page_disconnect from otree.channels.routing import channel_routing from channels.routing import include tracking_path = r'^/(?P<participant_code>\w+)/(?P<group_pk>\w+)$' wp_path = r'^/(?P<group_pk>\w+)$' tracking_routing = [ route("websocket.connect", ws_connect, path=tracking_path), route("websocket.receive", ws_message, path=tracking_path), route("websocket.disconnect", ws_disconnect, path=tracking_path), ] wait_page_routing = [ route("websocket.connect", wait_page_connect, path=wp_path), route("websocket.disconnect", wait_page_disconnect, path=wp_path), ] channel_routing += [ include(tracking_routing, path=r"^/tracking_channel"), include(wait_page_routing, path=r"^/wp_channel"), ]
from channels.routing import include from common.routing import channel_routing as common_cr from dalalbull.routing import channel_routing as dalalbull_cr channel_routing = [ include( dalalbull_cr, path=r'^/channel/dalalbull'), include( common_cr, path=r'^/channel'), ]
from channels.routing import include channel_routing = [include('messaging.routing.channel_routing')]
from channels.routing import include from .consumers import NotFoundConsumer channel_routing = [ # WS v1 include('common.routing.channel_routing', path=r'^/ws/v1/'), ] # 404 error channel_routing += [ NotFoundConsumer.as_route(path=r'^'), ]
route("websocket.connect", ws_connect), # Called when WebSockets disconnect route("websocket.disconnect", ws_disconnect), # Called when WebSockets get sent a data frame route("websocket.receive", ws_receive), ] # You can have as many lists here as you like, and choose any name. # Just refer to the individual names in the include() function. custom_routing = [ # Handling different chat commands (websocket.receive is decoded and put # onto this channel) - routed on the "command" attribute of the decoded # message. # route("notify.receive", set_notification_as_seen, command="^seen", ), # route("notify.receive", user_connected, command='^/user_connect/'), route("websocket.receive", user_connected), ] channel_routing = [ # Include sub-routing from an app. include(websocket_routing, path=r"^/lino"), # Custom handler for message sending (see Room.send_message). # Can't go in the include above as it's not got a `path` attribute to match on. include(custom_routing), # A default "http.request" route is always inserted by Django at the end of the routing list # that routes all unmatched HTTP requests to the Django view system. If you want lower-level # HTTP handling - e.g. long-polling - you can do it here and route by path, and let the rest # fall through to normal views. ]
def ws_path(websocket_classes): routers = get_default_router(websocket_classes) return include(routers)
from channels.routing import route from .consumers import dir_ws_message, dir_ws_connect, dir_ws_disconnect, dir_work_connect, dir_work_disconnect, dir_work_message from otree.channels.routing import channel_routing from channels.routing import include, route_class dir_auction_path = r'^/(?P<group_name>\w+)$' dir_work_path = r'^/(?P<worker_code>\w+)/(?P<player_pk>\w+)$' directauction_routing = [ route("websocket.connect", dir_ws_connect, path=dir_auction_path), route("websocket.receive", dir_ws_message, path=dir_auction_path), route("websocket.disconnect", dir_ws_disconnect, path=dir_auction_path), ] dir_workpage_routing = [ route("websocket.connect", dir_work_connect, path=dir_work_path), route("websocket.receive", dir_work_message, path=dir_work_path), route("websocket.disconnect", dir_work_disconnect, path=dir_work_path), ] channel_routing += [ include(directauction_routing, path=r"^/directauction"), include(dir_workpage_routing, path=r"^/dirworkpage"), ]
# -*- coding: utf-8 -*- from channels.routing import include from channels.routing import route from base.utils.app import get_base_routers from base_mission.check_api import channels_task from base_traffic.traffic.delay_traffic import delay_traffic from base_evaluation.delay_evaluation import evaluation_push routerpatterns = [ route('control', channels_task.control_message), route('traffic', delay_traffic), route('evaluation', evaluation_push), ] base_routers = get_base_routers() if base_routers: routerpatterns.append(include(base_routers, path=r'^/ws'))
from channels.routing import route, include import engine.consumers channel_routing = [include(engine.consumers.channel_routing)]
from channels.routing import route, include from chat.routing import channel_routing routing = [include(channel_routing, path=r'/')]
# -*- coding: utf-8 -*- # author: itimor from channels.routing import route, include from salts.router import salt_routing channel_routing = [ include(salt_routing, path='^/salt'), ]
# -*- coding: utf-8 -*- from channels.routing import include from catmaid.routing import channel_routing as catmaid_routes # Link connsumer functions to websockets. channel_routing = [include(catmaid_routes, path='^/channels')]
from channels.routing import route, include channel_routing = [ include('ssalt.routings.routing'), ]
from channels.routing import route, include channel_routing = [ #UNLIKE urls.py, path starts with / include('voxel_globe.websockets.routing.channel_routing', path=r'^/ws') ]
from channels.routing import route, include from channels.staticfiles import StaticFilesConsumer # noqa: ignore=F405 from caffe_app.consumers import ws_connect, ws_disconnect, ws_receive # routes defined for channel calls # this is similar to the Django urls, but specifically for Channels ws_routing = [ route('websocket.connect', ws_connect), route('websocket.receive', ws_receive), route('websocket.disconnect', ws_disconnect) ] channel_routing = [ include(ws_routing, path=r"^/ws/connect"), ]
from channels.routing import include import scoring.routing routes = [ include(scoring.routing.routes, path='^/websocket/'), ]
from channels.routing import include channel_routing = [ include('pygeppetto_server.routing.server_routing', path=r"^/org.geppetto.frontend/Geppetto"), ]
from channels.routing import route, route_class, include from haystack_channels.routing import channel_routing as haystack_routing def module_route(mod_route): return route(mod_route, mod_route) channel_routing = [ module_route("aristotle_mdr.contrib.channels.concept_changes.concept_saved"), module_route("aristotle_mdr.contrib.channels.concept_changes.new_comment_created"), module_route("aristotle_mdr.contrib.channels.concept_changes.new_post_created"), include(haystack_routing) ]
from channels.routing import route, include from .core import consumers from .core.routing import casemanager_routing routing = [ # You can use a string import path as the first argument as well. include(casemanager_routing, path=r"^/arbiter"), ]
from channels.routing import route, include from chat.routing import channel_routing routing = [ include(channel_routing, path=r"^/chat"), ]
# coding=utf-8 from channels import route from channels.routing import include chat_routing = [ route('websocket.connect', 'chat.consumers.chat_connect'), route('websocket.receive', 'chat.consumers.chat_message'), route('websocket.disconnect', 'chat.consumers.chat_disconnect'), ] routing = [ include(chat_routing, path=r'^/'), route('chat-messages', 'chat.consumers.chat_consumer'), ]