Пример #1
0
 def setup(self, environ):
     cfg = environ['pulsar.cfg']
     self.store = create_store(cfg.data_store)
     pubsub = self.store.pubsub()
     return WsgiHandler([
         Router('/', get=self.home_page),
         FileRouter('/favicon.ico', FAVICON),
         WebSocket('/message', TweetsWsHandler(pubsub, self.channel))
     ])
Пример #2
0
 def on_loaded(self, app, handler):
     templates = app.config['PAGE_TEMPLATES']
     dtemplates = OrderedDict()
     for id, template in enumerate(app.config['PAGE_TEMPLATES'], 1):
         if not template.key:
             template.key = 'Template %s' % id
         dtemplates[template.key] = template
     app.config['PAGE_TEMPLATES'] = dtemplates
     models = app.models
     path = app.config['PAGE_EDIT_URL']
     ws = WebSocket('<id>/updates', PageUpdates())
     handler.middleware.extend((EditPage(path, models.page,
                                         ws), CmsRouter('<path:path>')))
Пример #3
0
    def setup(self, environ):
        '''Called once only to setup the WSGI application handler.

        Check :ref:`lazy wsgi handler <wsgi-lazy-handler>`
        section for further information.
        '''
        cfg = environ['pulsar.cfg']
        loop = environ['pulsar.connection']._loop
        self.store = create_store(cfg.data_store, loop=loop)
        pubsub = self.store.pubsub(protocol=Protocol())
        channel = '%s_webchat' % self.name
        pubsub.subscribe(channel)
        return WsgiHandler([Router('/', get=self.home_page),
                            WebSocket('/message', Chat(pubsub, channel)),
                            Router('/rpc', post=Rpc(pubsub, channel),
                                   response_content_types=JSON_CONTENT_TYPES)])
Пример #4
0
    def setup(self, environ):
        '''Called once only by the WSGI server.

        It returns a :class:`.WsgiHandler` with three routes:

        * The base route served by the :meth:`home_page` method
        * The websocket route
        * A route for static files
        '''
        cfg = environ['pulsar.cfg']
        # Create the store and the pubsub handler
        self.store = create_store(cfg.data_store)
        pubsub = self.store.pubsub()
        # subscribe to channel
        ensure_future(self.subscribe(pubsub))
        return WsgiHandler([Router('/', get=self.home_page),
                            MediaRouter('/static', STATIC_DIR),
                            WebSocket('/message',
                                      TweetsWsHandler(pubsub, self.channel))])
Пример #5
0
    def setup(self, environ):
        '''Called once only to setup the WSGI application handler.

        Check :ref:`lazy wsgi handler <wsgi-lazy-handler>`
        section for further information.
        '''
        request = wsgi_request(environ)
        cfg = request.cache.cfg
        loop = request.cache._loop
        self.store = create_store(cfg.data_store, loop=loop)
        pubsub = self.store.pubsub(protocol=Protocol())
        channel = '%s_webchat' % self.name
        ensure_future(pubsub.subscribe(channel), loop=loop)
        return WsgiHandler([
            Router('/', get=self.home_page),
            WebSocket('/message', Chat(pubsub, channel)),
            Router('/rpc',
                   post=Rpc(pubsub, channel),
                   response_content_types=JSON_CONTENT_TYPES)
        ], [AsyncResponseMiddleware,
            GZipMiddleware(min_length=20)])
Пример #6
0
 def testHyBiKey(self):
     w = WebSocket('/', None)
     v = w.challenge_response('dGhlIHNhbXBsZSBub25jZQ==')
     self.assertEqual(v, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=")
Пример #7
0
 def testHyBiKey(self):
     w = WebSocket('/', None)
     v = w.challenge_response('dGhlIHNhbXBsZSBub25jZQ==')
     self.assertEqual(v, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=")
Пример #8
0
 def middleware(self, app):
     return [JsTests('jstests', WebSocket('socket', TestSocket()))]
Пример #9
0
 def __init__(self, route, handle, **kwargs):
     super(SockJs, self).__init__(route, **kwargs)
     self.handle = handle
     if self.websockets_enabled:
         self.add_child(WebSocket('/websocket', handle))
     self.add_child(SockTransports('/<server>/<session>/', handle))