def test_filters(self): """ Tests that filters catch things correctly. """ router = Router([ route("http.request", consumer_1, path=r"^/chat/$"), route("http.disconnect", consumer_2), route("http.request", consumer_3), ]) # Filter hit self.assertRoute( router, channel="http.request", content={"path": "/chat/"}, consumer=consumer_1, kwargs={}, ) # Fall-through self.assertRoute( router, channel="http.request", content={}, consumer=consumer_3, kwargs={}, ) self.assertRoute( router, channel="http.request", content={"path": "/liveblog/"}, consumer=consumer_3, kwargs={}, )
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_positional_pattern(self): """ Tests that regexes with positional groups are rejected. """ with self.assertRaises(ValueError): Router([ route("http.request", consumer_1, path=r"^/chat/([^/]+)/$"), ])
def test_channels(self): """ Tests that the router reports channels to listen on correctly """ router = Router([ route("http.request", consumer_1, path=r"^/chat/$"), route("http.disconnect", consumer_2), route("http.request", consumer_3), ]) # Initial check self.assertEqual( router.channels, {"http.request", "http.disconnect"}, ) # Dynamically add route, recheck router.add_route(route("websocket.receive", consumer_1)) self.assertEqual( router.channels, {"http.request", "http.disconnect", "websocket.receive"}, )
def calc_routes(url_list, parent_pattern=None): result = [] if parent_pattern is None: parent_pattern = '' for url_path in url_list: if isinstance(url_path, RegexURLResolver): result += calc_routes( url_path.url_patterns, '{0}{1}'.format(parent_pattern, url_path.regex.pattern)) elif isinstance(url_path, RegexURLPattern): result.append( route(url_path.default_args['method'], url_path.callback, path='{0}{1}'.format(parent_pattern, url_path.regex.pattern).replace( '//', '/'))) return result
from api import socketconsumers from channels.routing import route channel_routing = [ route('websocket.receive', socketconsumers.ws_message), route('websocket.disconnect', socketconsumers.ws_disconnect), ]
from channels.routing import route from app.consumers import ws_connect, ws_receive, ws_disconnect channel_routing = [ route( 'websocket.connect', ws_connect, path=r'^/games/(?P<game_id>[0-9]+)/(?P<user_id>[0-9]+)/$' ), route( 'websocket.receive', ws_receive, path=r'^/games/(?P<game_id>[0-9]+)/(?P<user_id>[0-9]+)/$' ), route( 'websocket.disconnect', ws_disconnect, path=r'^/games/(?P<game_id>[0-9]+)/(?P<user_id>[0-9]+)/$' ), ]
from channels.routing import route from friendsbook.consumers import ws_connect, ws_disconnect, ws_receive channel_routing = [ route('websocket.connect', ws_connect), route('websocket.receive', ws_receive), route('websocket.disconnect', ws_disconnect), ]
from channels.routing import route channel_routing = [ route('websocket.connect', "communication.consumers.ws_connect"), route('websocket.receive', "communication.consumers.ws_receive"), route('websocket.disconnect', "communication.consumers.ws_disconnect"), ]
# Fake consumers and routing sets that can be imported by string def consumer_1(): pass def consumer_2(): pass def consumer_3(): pass chatroom_routing = [ route("websocket.connect", consumer_2, path=r"^/chat/(?P<room>[^/]+)/$"), route("websocket.connect", consumer_3, path=r"^/mentions/$"), ] chatroom_routing_noprefix = [ route("websocket.connect", consumer_2, path=r"/chat/(?P<room>[^/]+)/$"), route("websocket.connect", consumer_3, path=r"/mentions/$"), ] class RoutingTests(SimpleTestCase): """ Tests that the router's routing code works correctly. """ def assertRoute(self, router, channel, content, consumer, kwargs=None):
from channels.routing import route from texas.test_consumer import * channel_routing = [ route('websocket.receive', ws_msg), route('websocket.connect', ws_add), route('websocket.disconnect',ws_disconnect), ]
from channels.routing import route channel_routing = [ route("http.request", "myapp.consumers.http_consumer"), ]
# -*- coding: utf-8 -*- from channels.routing import route channel_routing = [ route("websocket.connect", 'soc.consumers.ws_add', path=r"^/dashboard/$"), route("websocket.receive", 'soc.consumers.ws_message', path=r"^/dashboard/$"), route("websocket.disconnect", 'soc.consumers.ws_disconnect', path=r"^/dashboard/$"), ]
"""Channel routes.""" from channels.routing import route channel_routing = [ route("websocket.connect", "alarm.consumers.ws_auth"), route("websocket.receive", "alarm.consumers.ws_echo"), route("websocket.disconnect", "alarm.consumers.ws_disconnect"), route("vision.images", "vision.consumers.handle_image"), ]
from channels.routing import route from articles.consumers import ws_message channel_routing = [ route("websocket.receive", ws_message), ]
from channels.routing import route from lily.consumers import LilyConsumer, LilyViewConsumer, LilyStaticFilesConsumer from lily.settings import settings channel_routing = [ LilyConsumer.as_route(), ] if settings.DEBUG: channel_routing.insert(0, route("http.request", LilyStaticFilesConsumer())) else: channel_routing.insert(0, route("http.request", LilyViewConsumer()))
from channels.routing import route from pyconguide.consumers import ws_connect, ws_message channel_routing = [ route("websocket.connect", ws_connect), route("websocket.receive", ws_message), ]
from channels.routing import route from .consumers import hello channel_routing = [ route('background-hello', hello), ]
from channels.routing import route from tweety.consumers import ws_add, ws_message, ws_disconnect channel_routing = [ route("websocket.connect", ws_add), route("websocket.receive", ws_message), route("websocket.disconnect", ws_disconnect), ]
from channels.routing import route, route_class from numbas_lti import consumers channel_routing = [ route("websocket.connect",consumers.ws_connect, path=r'^/websocket/attempt/(?P<pk>\d+)/scorm_api$'), route("websocket.disconnect",consumers.ws_disconnect, path=r'^/websocket/attempt/(?P<pk>\d+)/scorm_api$'), route("websocket.receive",consumers.scorm_set_element, path=r'^/websocket/attempt/(?P<pk>\d+)/scorm_api$'), route_class(consumers.AttemptScormListingConsumer, path=r'^/websocket/attempt/(?P<pk>\d+)/scorm_listing$'), route("report.all_scores",consumers.report_scores), route("editorlink.update_cache",consumers.update_editorlink), ]
from channels.routing import route from .consumers import ws_receive, ws_connect, worker public_routing = [ route('websocket.connect', ws_connect), route('websocket.receive', ws_receive), ] internal_routing = [route('prog-rocker', worker)]
from channels.routing import route channel_routing = [ route('websocket.connect', 'chat.consumers.ws_connect'), route('websocket.disconnect', 'chat.consumers.ws_disconnect'), route('websocket.receive', 'chat.consumers.ws_message'), ]
def consumer_3(): pass class TestClassConsumer(BaseConsumer): method_mapping = { "test.channel": "some_method", } def some_method(self, message, **kwargs): pass chatroom_routing = [ route("websocket.connect", consumer_2, path=r"^/chat/(?P<room>[^/]+)/$"), route("websocket.connect", consumer_3, path=r"^/mentions/$"), ] chatroom_routing_nolinestart = [ route("websocket.connect", consumer_2, path=r"/chat/(?P<room>[^/]+)/$"), route("websocket.connect", consumer_3, path=r"/mentions/$"), ] class_routing = [ route_class(TestClassConsumer, path=r"^/foobar/$"), ] class RoutingTests(SimpleTestCase): """
from channels.routing import route from . import consumers routes = [ route('websocket.connect', consumers.data_entry_connect, path='^(?P<game_id>\d+)/score/$'), route('websocket.receive', consumers.data_entry_receive, path='^(?P<game_id>\d+)/score/$'), route('websocket.disconnect', consumers.data_entry_disconnect, path='^(?P<game_id>\d+)/score/$'), ]
from channels.routing import route channel_routing = [ route("websocket.connect", "chatrooms.consumers.ws_connect"), route("websocket.receive", "chatrooms.consumers.ws_receive"), route("websocket.disconnect", "chatrooms.consumers.ws_disconnect"), ]
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 from ChatApp import consumers channel_routing = [ route('websocket.connect', consumers.ws_add, path=r'^/chat/$'), route('websocket.receive', consumers.ws_message, path=r'^/chat/$'), route('websocket.disconnect', consumers.ws_disconnect, path=r'^/chat/$') ]
''' Created on 2016-11-25 @author: Polly ''' ''' from channels.routing import route channel_routing = [ route("http.request", "Server.consumers.http_consumer"), ] ''' from channels.routing import route from Server.consumers import ws_connect, ws_receive_search, ws_receive_create, ws_disconnect channel_routing = [ #route("websocket.receive", ws_message, path="^/chat/"), #route("websocket.connect", ws_connect), route("websocket.connect", ws_connect), route("websocket.receive", ws_receive_create, path="^/indexCreate/"), route("websocket.receive", ws_receive_search, path="^/indexSearch/"), route("websocket.disconnect", ws_disconnect), ]
# from channels.auth import AuthMiddlewareStack from django.conf.urls import url from . import consumers from channels.routing import route # from channels.routing import ProtocolTypeRouter, URLRouter import re websocket_urlpatterns = [ route('websocket.connect', consumers.chat_connect), route('websocket.disconnect', consumers.chat_disconnect), route('websocket.receive', consumers.chat_receive), ] # application = ProtocolTypeRouter({ # 'websocket': AuthMiddlewareStack( # URLRouter( # websocket_urlpatterns # ) # ), # })
from channels.routing import route from . import websocket_handler channel_routing = [ # Called when WebSockets connect route("websocket.connect", websocket_handler.open_test, path=r'^/ws'), # Called when WebSockets get sent a data frame route("websocket.receive", websocket_handler.req_handler, path=r'^/ws'), # Called when WebSockets disconnect # route("websocket.disconnect", onlineshellmanager.build_session), ]
from channels.routing import route from channelizer.consumers import ws_connect, ws_disconnect channel_routing = [ route('websocket.connect', ws_connect), route('websocket.disconnect', ws_disconnect), ]
from channels.routing import route, route_class from otree.channels import consumers from otree.extensions import get_extensions_modules channel_routing = [ route('otree.create_session', consumers.create_session), # WebSockets route_class( consumers.WaitPage, path=r'^/wait_page/(?P<params>[\w,]+)/$'), route_class( consumers.GroupByArrivalTime, path=r'^/group_by_arrival_time/(?P<params>[\w,\.]+)/$'), route_class( consumers.AutoAdvance, path=r'^/auto_advance/(?P<params>[\w,]+)/$'), route_class(consumers.WaitForSession, path=r'^/wait_for_session/(?P<pre_create_id>\w+)/$'), route_class( consumers.RoomParticipant, path=r'^/wait_for_session_in_room/(?P<params>[\w,]+)/$'), route_class( consumers.RoomAdmin, path=r'^/room_without_session/(?P<room>\w+)/$'), route_class( consumers.BrowserBotsLauncher,
from channels.routing import route from chat.consumers import ws_add, ws_message, ws_disconnect # In routing.py from channels.routing import route channel_routing = [ route("http.request", "chat.consumers.http_consumer"), route("websocket.connect", ws_add), route("websocket.receive", ws_message), route("websocket.disconnect", ws_disconnect), ]
from channels.routing import route from otree.channels import consumers channel_routing = [ route( 'websocket.connect', consumers.connect_wait_page, path=r'^/wait_page/(?P<params>[\w,]+)/$'), route( 'websocket.disconnect', consumers.disconnect_wait_page, path=r'^/wait_page/(?P<params>[\w,]+)/$'), route( 'websocket.connect', consumers.connect_auto_advance, path=r'^/auto_advance/(?P<params>[\w,]+)/$'), route( 'websocket.disconnect', consumers.disconnect_auto_advance, path=r'^/auto_advance/(?P<params>[\w,]+)/$'), route('websocket.connect', consumers.connect_wait_for_session, path=r'^/wait_for_session/(?P<pre_create_id>\w+)/$'), route('websocket.disconnect', consumers.disconnect_wait_for_session, path=r'^/wait_for_session/(?P<pre_create_id>\w+)/$'), route('otree.create_session', consumers.create_session) ]
from channels.routing import route from . import consumers channel_routing = [ route('websocket.connect', consumers.waiting, path=r'^waiting/(?P<page>[\w|\W]+)/$'), ]
from channels.routing import route channel_routing = [ route('http.request', 'chat.consumers.http_consumer'), route("websocket.connect", 'chat.consumers.ws_connect'), route("websocket.receive", 'chat.consumers.ws_message'), route("websocket.disconnect", 'chat.consumers.ws_disconnect'), ]
from channels.routing import route from .consumers import ( ws_job_status_connect, ws_job_status_disconnect, ws_job_log_connect, ws_job_log_disconnect, ) channel_routing = [ route('websocket.connect', ws_job_status_connect, path=r'^/job-user/$'), route('websocket.disconnect', ws_job_status_disconnect, path=r'^/job-user/$'), route('websocket.connect', ws_job_log_connect, path=r'^/job-log/(?P<job_pk>[0-9]+)/$'), route('websocket.disconnect', ws_job_log_disconnect, path=r'^/job-log/(?P<job_pk>[0-9]+)/$'), ]
router.register(r'products', ProductViewSet, base_name='products') router.register(r'productstatuses', ProductStatusViewSet, base_name='productstatuses') router.register(r'workflows', WorkflowViewSet, base_name='workflows') router.register(r'runs', RunViewSet, base_name='runs') router.register(r'tasks', TaskViewSet, base_name='tasks') router.register(r'taskfields', TaskFieldViewSet, base_name='taskfields') router.register(r'filetemplates', FileTemplateViewSet, base_name='filetemplates') router.register(r'copyfiles', CopyFileDriverViewSet, base_name='copyfiles') router.register(r'triggers', TriggerViewSet, base_name='triggers') router.register(r'triggersets', TriggerSetViewSet, base_name='triggersets') router.register(r'subscriptions', TriggerSubscriptionViewSet, base_name='subscriptions') router.register(r'alerts', TriggerAlertStatusViewSet, base_name='alerts') urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^users/token/', obtain_jwt_token), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), url(r'^crm/user/', CRMUserView.as_view()), url(r'^crm/project/update/', CRMUpdateProjectView.as_view()), url(r'^crm/account/update/', CRMUpdateAccountView.as_view()), url(r'^crm/project/', CRMProjectView.as_view()), url(r'^crm/link/', CRMLinkView.as_view()), url(r'^docs/', include('rest_framework_docs.urls')), url(r'^', include(router.urls)), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) channel_routing = [ route('send-email', send_email) ]
from channels.routing import route from idona.consumers import ws_connect, ws_disconnect, mqtt_message channel_routing = [ route('websocket.connect', ws_connect), route('websocket.disconnect', ws_disconnect), route('mqtt.sub', mqtt_message), ]
from channels.routing import route from market.consumers import ws_message, ws_connect, ws_disconnect, broker_msg, post_work channel_routing = [ route("websocket.connect", ws_connect), route("websocket.receive", ws_message), route("websocket.disconnect", ws_disconnect), route("web", broker_msg), route("post-work", post_work) ]
from chat import consumers from django.conf.urls import include, url from channels.routing import route from django.contrib import admin #application = ProtocolTypeRouter({}) channel_routing = [ route('websocket.connect', consumers.ws_connect_video, path=r'^/(?P<room1>[0-9]+)/video$'), route('websocket.disconnect', consumers.ws_disconnect_video, path=r'^/(?P<room1>[0-9]+)/video$'), route('websocket.receive', consumers.ws_receive_video, path=r'^/(?P<room1>[0-9]+)/video$'), route('websocket.receive', consumers.ws_receive, path=r'^/(?P<room>[0-9]+)$'), route('websocket.connect', consumers.ws_connect, path=r'^/(?P<room>[0-9]+)$'), route('websocket.disconnect', consumers.ws_disconnect, path=r'^/(?P<room>[0-9]+)$') ]
from channels.routing import route from hello import consumers channel_routing = [ route('notify', consumers.notify), ]
from chat import consumers from channels.routing import route socket_routing = [ route("websocket.connect", consumers.ws_connect), route("websocket.receive", consumers.ws_receive), route("websocket.disconnect", consumers.ws_disconnect), ]
# coding : utf-8 from channels.routing import route from conc.consumers import ws_connect, ws_disconnect, ws_receive channel_routing = [ route('websocket.connect', ws_connect), route('websocket.disconnect', ws_disconnect), route('websocket.receive', ws_receive) ]
from channels.routing import include, route 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 import include, routing from tntapp.consumers import ws_connect, ws_receive, ws_disconnect ws_routing = [ routing.route("websocket.connect", ws_connect), routing.route("websocket.receive", ws_receive), routing.route("websocket.disconnect", ws_disconnect), ] channel_routing = [ include(ws_routing, path=r"^/sync"), ]
from channels.routing import route from dashboard.consumers import ws_message channel_routing = [ route("websocket.receive", ws_message), ]
from channels.routing import route from .consumers import message_consumer channel_routing = [ route("slack.rtm.message", message_consumer) ]
from channels.routing import route from lovelive.consumers import ws_add, ws_echo, ws_disconnect channel_routing = [ route('websocket.connect', ws_add, path=r'^/lovelive/channel/(?P<room>\w+)$'), route('websocket.receive', ws_echo), route("websocket.disconnect", ws_disconnect), ]
from channels.routing import route from .consumers import ws_add, ws_disconnect channel_routing = [ route("websocket.connect", ws_add), route("websocket.disconnect", ws_disconnect), ]
from channels.routing import route channel_routing = [ route("websocket.connect", "core.consumers.ws_connect"), route("websocket.receive", "core.consumers.ws_message"), route("websocket.disconnect", "core.consumers.ws_disconnect"), ]
from channels.routing import route from .consumers import ws_message, ws_job_connect, ws_disconnect channel_routing = [ route("websocket.connect", ws_job_connect, path=r"^/ws/(?P<group_id>[a-zA-Z0-9_-]+)/$"), # noqa route("websocket.receive", ws_message, path=r"^/ws/(?P<group_id>[a-zA-Z0-9_-]+)/$"), # noqa route( "websocket.disconnect", ws_disconnect, path=r"^/ws/(?P<group_id>[a-zA-Z0-9_-]+)/$", ), # noqa ]
from channels.routing import route from .some import ws_connect, ws_disconnect, ws_message list_routing = [ route("websocket.connect", ws_connect), route("websocket.disconnect", ws_disconnect), route("websocket.receive", ws_message), ]
from channels.routing import route, route_class from chat import consumers channel_routing = [ route("websocket.connect", consumers.ws_connect), route("websocket.receive", consumers.ws_message), route("websocket.disconnect", consumers.ws_disconnect), ]