Exemple #1
0
 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),
         route_class(TestClassConsumer),
     ])
     # Initial check
     self.assertEqual(
         router.channels,
         {"http.request", "http.disconnect", "test.channel"},
     )
     # Dynamically add route, recheck
     router.add_route(route("websocket.receive", consumer_1))
     self.assertEqual(
         router.channels,
         {"http.request", "http.disconnect", "websocket.receive", "test.channel"},
     )
from channels.routing import route_class
from .consumers import LotteryTracker

channel_routing = [
    route_class(
        LotteryTracker,
        path=LotteryTracker.url_pattern,
    )
]
Exemple #3
0
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,
                path=r'^/browser_bots_client/(?P<session_code>\w+)/$'),
    route_class(consumers.BrowserBot, path=r'^/browser_bot_wait/$'),
]

# TODO: perf issue. this takes 0.1-0.5 seconds.
for extensions_module in get_extensions_modules('routing'):
    channel_routing += getattr(extensions_module, 'channel_routing', [])
Exemple #4
0
from channels.routing import route, route_class
from channels.staticfiles import StaticFilesConsumer
from . import consumers

channel_routing = [
    route_class(consumers.NotificationConsumer, path=r"^notifications/"),
]
"""
websocket_routing = [
    route("websocket.connect", consumers.ws_connect),
    route("websocket.receive", consumers.ws_receive),
    route("websocket.disconnect", consumers.ws_disconnect),
]   

custom_routing = [
    consumers.NotificationConsumer.as_route(path=r"^"),
]
"""
"""


custom_routing = [
    route("notification.receive", notification_send, command="^send$"),
    route("notification.receive", notification_join, command="^join$"),
    route("notification.receive", notification_leave, command="^leave$"),
]
"""
Exemple #5
0
from channels.routing import route_class
from .consumers import WPTracker

channel_routing = [
    route_class(WPTracker, path=WPTracker.url_pattern),
]
Exemple #6
0
from channels.routing import route_class

from vcta_service.consumers import Demultiplexer

channel_routing = [
    route_class(Demultiplexer, path="^/api/v1/ws"),
]
Exemple #7
0
from channels.routing import route_class 
from games.consumers import GameConsumer, LobbyConsumer

channel_routing = [
    route_class(LobbyConsumer,
                path=r'^/games/$'),
    route_class(GameConsumer,
                path=r'^/games/game_(?P<game_id>[0-9]+)/$'),
]
Exemple #8
0
from channels.routing import route_class
from .consumers import BubbleTracker

channel_routing = [
    route_class(BubbleTracker, path=BubbleTracker.url_pattern),
]
Exemple #9
0
"""
   Routing Module with all Demultiplexers and channel_routing for djnago-channels
"""

from channels.generic.websockets import WebsocketDemultiplexer
from channels.routing import route_class

from manager.binding import (ActivityBinding, AttendeeAttendanceDateBinding,
                             EventBinding, EventUserAttendanceDateBinding,
                             InstallationBinding)


class APIDemultiplexer(WebsocketDemultiplexer):
    consumers = {
        'activities': ActivityBinding.consumer,
        'attendeeattendancedates': AttendeeAttendanceDateBinding.consumer,
        'events': EventBinding.consumer,
        'eventuserattendancedates': EventUserAttendanceDateBinding.consumer,
        'installations': InstallationBinding.consumer,
    }

    def connection_groups(self, **kwargs):
        return ['activities-updates', 'attendeeattendancedates-updates',
                'events-updates', 'eventuserattendancedates-updates',
                'installation-updates']


channel_routing = [
    route_class(APIDemultiplexer, path='^/updates/$')
]
Exemple #10
0
from channels.routing import route_class

from chat.consumers import ChatConsumer

channel_routing = [
    route_class(ChatConsumer),
]
Exemple #11
0
# coding=utf-8
from channels.routing import route, route_class
from channels_test.consumers import *

channel_routing = [
    #route("http.request", "channels_test.consumers.http_consumer"),
    route_class(Chat3Consumer, path="^/chat/"),
    #route("websocket.receive", ws_message),
]
from app.consumers import ShoutboxConsumer
from channels.routing import route_class

channel_routing = [
    route_class(ShoutboxConsumer, path=r"^/shoutbox"),
]

Exemple #13
0
from channels.routing import route_class
from .apps.bus.consumers import BusConsumer

channel_routing = [route_class(BusConsumer, path=r"^/bus/")]
Exemple #14
0
# coding=utf-8
from channels.routing import route, route_class
from .consumers import *

channel_routing = [
    route_class(SpiderConsumer, path="^/spider/"),
]
Exemple #15
0
from channels.routing import route, route_class
from channels.staticfiles import StaticFilesConsumer
from game import consumers

# routes defined for channel calls
# this is similar to the Django urls, but specifically for channels
channel_routing = [
    route_class(consumers.LobbyConsumer, path=r"^/lobby/"),
    route("websocket.receive", consumers.LobbyConsumer.receive)
]
Exemple #16
0
# coding: utf-8
__author__ = "HanQian"

# routing.py文件其实就是个表单,功能和Django原来的urls.py文件一样,
# 不过这里使用的不是URL,而是请求的类型。

from channels.routing import route, route_class
from fortress.consumers import Webterminal, TerminalMonitor
channel_routing = [
    route_class(Webterminal),
    # route_class(CommandExecute,path= r'^/execute'),
    route_class(TerminalMonitor,
                path=r'^/monitor/(?P<channel>\w+-\w+-\w+-\w+-\w+-\w+)'),
]
Exemple #17
0
from channels.routing import route, route_class

from otree.channels import consumers
from otree.extensions import get_extensions_modules
from channels.routing import route, route_class


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(
from channels import route
from channels.generic.websockets import WebsocketDemultiplexer
from channels.routing import route_class

from random_generator import consumers
from random_generator.bindings import PointsBinding


class APIDemultiplexer(WebsocketDemultiplexer):

    consumers = {'points': PointsBinding.consumer}


channel_routing = [
    route('websocket.disconnect', consumers.ws_disconnect),
    route_class(APIDemultiplexer),
]
from channels.routing import route_class

from .consumers import SignalConsumer


channel_routing = [
    route_class(SignalConsumer, path=r"/signals/recieve"),
]
Exemple #20
0
    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):
    """
    Tests that the router's routing code works correctly.
    """
    def assertRoute(self, router, channel, content, consumer, kwargs=None):
        """
        Asserts that asking the `router` to route the `content` as a message
        from `channel` means it returns consumer `consumer`, optionally
        testing it also returns `kwargs` to be passed in

        Use `consumer` = None to assert that no route is found.
        """
Exemple #21
0
    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):
    """
    Tests that the router's routing code works correctly.
    """

    def assertRoute(self, router, channel, content, consumer, kwargs=None):
        """
        Asserts that asking the `router` to route the `content` as a message
        from `channel` means it returns consumer `consumer`, optionally
        testing it also returns `kwargs` to be passed in

        Use `consumer` = None to assert that no route is found.
Exemple #22
0
from channels.routing import route_class
from .consumers import LoggerConsumer

channel_routing = [
  route_class(LoggerConsumer, path=r'^/logger/(?P<websocket_key>[a-z0-9]+)/$'),
]
Exemple #23
0
from channels.routing import route_class

from versus.confrontations.bindings import (CategoryBinding, TopicBinding,
                                            OptionBinding, OpinionBinding,
                                            RecomendationBinding,
                                            CommentsBinding)

from versus.confrontations.auth import path_token_user


class APIDemultiplexer(WebsocketDemultiplexer):
    @path_token_user
    def connect(self, message, **kwargs):
        print(message)

    @path_token_user
    def disconnect(self, message, **kwargs):
        print(message)

    consumers = {
        'categories': CategoryBinding.consumer,
        'topics': TopicBinding.consumer,
        'options': OptionBinding.consumer,
        'opinions': OpinionBinding.consumer,
        'recommendations': RecomendationBinding.consumer,
        'comments': CommentsBinding.consumer
    }


channel_routing = [route_class(APIDemultiplexer)]
from graphene_django_subscriptions.consumers import GraphqlAPIDemultiplexer
from channels.routing import route_class
from dashboard.subscriptions import SnippetSubscription


class CustomAppDemultiplexer(GraphqlAPIDemultiplexer):
    consumers = {
        'snippets': SnippetSubscription.get_binding().consumer,
    }


app_routing = [route_class(CustomAppDemultiplexer)]
Exemple #25
0
        self.message.reply_channel.send({'accept': True})

    def receive(self, text=None, bytes=None, **kw):
        """接收到信息时调用的函数
        """
        my_data = text + '\n'
        print(len(my_data))
        MyConsumer.chan.send(my_data)
        time.sleep(0.5)
        send_data = ''
        print(MyConsumer.chan.recv_ready())
        while True:

            if MyConsumer.chan.recv_ready():
                data = MyConsumer.chan.recv(9999)
                print(data)
                send_data = send_data + str(data, encoding='utf-8')
            else:
                break
        self.send(text=send_data.replace(text, ''), bytes=bytes)

    def disconnect(self, message, **kw):
        """断开连接时将会被调用
        """
        MyConsumer.chan.close()


channel_routing = [
    route_class(consumer.webterminal, path=r"/webterminal/$"),
]
Exemple #26
0
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),
]
Exemple #27
0
from channels.routing import route_class
from onadata.apps.fieldsight.consumers import OneToOneConsumer, GroupConsumer, NotificationConsumer, \
    ProjectLevelConsumer, SiteLevelConsumer

channel_routing = [
    route_class(OneToOneConsumer, path=r"^/chat/(?P<pk>[0-9]+)/$"),
    route_class(GroupConsumer, path=r"^/groupchat/(?P<group_id>[^/]+)/$"),
    route_class(NotificationConsumer, path=r"^/notify/(?P<pk>[0-9]+)/$"),
    route_class(ProjectLevelConsumer, path=r"^/project/(?P<pk>[0-9]+)/$"),
    route_class(SiteLevelConsumer, path=r"^/site/(?P<pk>[0-9]+)/$"),
]
Exemple #28
0
from channels.routing import route, route_class
from .consumers import TaskTracker

# NOTE: otree_extensions is part of
# otree-core's private API, which may change at any time.
channel_routing = [
    route_class(TaskTracker, path=TaskTracker.url_pattern),

]
Exemple #29
0
from graphene_django_subscriptions.consumers import GraphqlAPIDemultiplexer
from channels.routing import route_class
from .schema import UserSubscription

class CustomApp(GraphqlAPIDemultiplexer):
    consumers = {
        'users':UserSubscription.get_binding().consumer
    }

app_routing = [
    route_class(CustomApp)
]
Exemple #30
0
from channels.routing import route, route_class
from api.consumers import Demultiplexer

channel_routing = [
    route_class(Demultiplexer, path="^/ws/"),
]


Exemple #31
0
from channels.routing import route_class
from utils.websocket.dummy_consumer import DummyConsumer
from utils.websocket.subscription import SubscriptionConsumer


channel_routing = [
    route_class(DummyConsumer, path=r'/test/$'),
    route_class(SubscriptionConsumer, path=r'/subscribe/$'),
]
Exemple #32
0
from channels.routing import route_class
from .consumers import JsonLoader

channel_routing = [
    route_class(JsonLoader, path=JsonLoader.url_pattern),
]
Exemple #33
0
from graphene_django_subscriptions.consumers import GraphqlAPIDemultiplexer
from channels.routing import route_class
from rooms.subscriptions import RoomSubscription, MessageSubscription


class RoomsDemultiplexer(GraphqlAPIDemultiplexer):
    consumers = {
        'rooms': RoomSubscription.get_binding().consumer,
        'messages': MessageSubscription.get_binding().consumer
    }


app_routing = [route_class(RoomsDemultiplexer)]
Exemple #34
0
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,
Exemple #35
0
from channels.routing import route_class
from onadata.apps.fieldsight.consumers import OneToOneConsumer, GroupConsumer, NotificationConsumer

channel_routing = [
    route_class(OneToOneConsumer, path=r"^/chat/(?P<pk>[0-9]+)/$"),
    route_class(GroupConsumer, path=r"^/groupchat/(?P<group_id>[^/]+)/$"),
    route_class(NotificationConsumer, path=r"^/notify/(?P<pk>[0-9]+)/$"),
]
Exemple #36
0
from channels.routing import route_class, route
from graphql_ws.django_channels import GraphQLSubscriptionConsumer


def ws_GQL_connect(message):
    message.reply_channel.send({"accept": True})


@channel_session
def ws_GQLData(message):
    print("message", message.__dict__)
    clean = json.loads(message.content['text'])
    query = clean.get('payload').get('query')
    foovar = clean.get('variables')
    kwargs = {'context_value': message}
    print("query", query)
    result = schema.execute(query,
                            variable_values=foovar,
                            allow_subscriptions=True,
                            **kwargs)
    print("result", result.data)
    message.reply_channel.send(
        {'text': str({'data': json.loads(json.dumps(result.data))})})


channel_routing = [
    # route('websocket.connect', ws_GQL_connect, path=r"^/subscriptions"),
    # route('websocket.receive', ws_GQLData, path=r"^/subscriptions"),
    route_class(GraphQLSubscriptionConsumer, path=r"^/subscriptions"),
]
Exemple #37
0
from channels.routing import route_class
from .apps.bus.consumers import BusConsumer

channel_routing = [
    route_class(BusConsumer, path=r"^/bus/")
]
Exemple #38
0
from trans.consumers import ExConsumer
from otree.channels.routing import channel_routing
from channels.routing import route_class

ex_path = r"^/ex/(?P<pid>\w+)/(?P<pk>\w+)$"

channel_routing += [
    route_class(ExConsumer, path=ex_path),
]
Exemple #39
0
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),
]
Exemple #40
0

class LinkTagDemultiplexer(WebsocketDemultiplexer):
    consumers = {'linktags': LinkTagBinding.consumer}

    def connection_groups(self, **kwargs):
        return ['linktag-updates']


class LinkDemultiplexer(WebsocketDemultiplexer):
    consumers = {'links': LinkBinding.consumer}

    def connection_groups(self, **kwargs):
        return ['link-updates']


class TagDemultiplexer(WebsocketDemultiplexer):
    consumers = {'tags': TagBinding.consumer}

    def connection_groups(self, **kwargs):
        return ['tag-updates']


# pylint: disable=invalid-name
channel_routing = [
    route_class(APIDemultiplexer, path='^/updates/$'),
    route_class(LinkTagDemultiplexer, path='^/updates/linktags/$'),
    route_class(LinkDemultiplexer, path='^/updates/links/$'),
    route_class(TagDemultiplexer, path='^/updates/tags/$'),
]
from channels.routing import route, route_class

from .consumers import ws_add, ws_disconnect, FrontendEditConsumer, SignalConsumer

channel_widget_http = [
    route_class(FrontendEditConsumer, path=r"/widgets/update"),
    route_class(SignalConsumer, path=r"/signals/recieve"),
]

channel_widget_routing = [
    route("websocket.connect", ws_add),
    route("websocket.disconnect", ws_disconnect),
]
Exemple #42
0
from channels.routing import route_class
from .consumers import MarketTracker

channel_routing = [
    route_class(MarketTracker, path=MarketTracker.url_pattern),

]
Exemple #43
0
from channels.routing import route_class
from .consumers import NetworkVoting

channel_routing = [
    route_class(NetworkVoting, path=NetworkVoting.url_pattern),
]
Exemple #44
0
from graphene_django_subscriptions.consumers import GraphqlAPIDemultiplexer
from channels.routing import route_class
from users.subscriptions import UserSubscription


class UsersDemultiplexer(GraphqlAPIDemultiplexer):
    consumers = {
        'users': UserSubscription.get_binding().consumer,
    }


app_routing = [
    route_class(UsersDemultiplexer)
]
Exemple #45
0
from channels.routing import route_class
from spirits.consumers import FightConsumer

routing = [
    route_class(FightConsumer),
]