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)) ])
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>')))
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)])
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))])
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)])
def testHyBiKey(self): w = WebSocket('/', None) v = w.challenge_response('dGhlIHNhbXBsZSBub25jZQ==') self.assertEqual(v, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=")
def middleware(self, app): return [JsTests('jstests', WebSocket('socket', TestSocket()))]
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))