예제 #1
0
 def test_path_method(self):
     router = Router('/root', Router('a', get=lambda r: ['route a']))
     self.assertEqual(router.path(), '/root')
     self.assertEqual(router.route.is_leaf, True)
     child, args = router.resolve('root/a')
     self.assertFalse(args)
     self.assertEqual(child.parent, router)
     self.assertEqual(child.path(), '/root/a')
예제 #2
0
파일: router.py 프로젝트: LJS109/pulsar
 def test_path_method(self):
     router = Router('/root',
                     Router('a', get=lambda r: ['route a']))
     self.assertEqual(router.path(), '/root')
     self.assertEqual(router.route.is_leaf, True)
     child, args = router.resolve('root/a')
     self.assertFalse(args)
     self.assertEqual(child.parent, router)
     self.assertEqual(child.path(), '/root/a')
예제 #3
0
 def test_path_method(self):
     router = Router('/root',
                     Router('a', get=lambda r: ['route a']))
     self.assertEqual(router.path(), '/root')
     self.assertEqual(router.route.is_leaf, True)
     hnd = router.resolve('/root/a', 'GET')
     self.assertFalse(hnd.urlargs)
     self.assertEqual(hnd.router.parent, router)
     self.assertEqual(hnd.router.path(), '/root/a')
예제 #4
0
 def test_path_method(self):
     router = Router('/root',
                     Router('a', get=lambda r: ['route a']))
     self.assertEqual(router.path(), '/root')
     self.assertEqual(router.route.is_leaf, True)
     hnd = router.resolve('/root/a', 'GET')
     self.assertFalse(hnd.urlargs)
     self.assertEqual(hnd.router.parent, router)
     self.assertEqual(hnd.router.path(), '/root/a')
예제 #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.
        '''
        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)])
예제 #6
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))
     ])
예제 #7
0
    def setup(self, environ):
        # only post allowed by the JSON RPC handler
        api = Producer(self.cfg)
        handler = TaskQueueRpc(api)
        for consumer in api.consumers:
            rpc = consumer.rpc()
            if rpc:
                handler.putSubHandler(consumer.name, rpc)

        request = [Router('/', post=handler)]
        response = [GZipMiddleware(200)]
        return WsgiHandler(middleware=request, response_middleware=response)
예제 #8
0
파일: manage.py 프로젝트: zzzz123321/pulsar
    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)])
예제 #9
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))])
예제 #10
0
파일: manage.py 프로젝트: zzzz123321/pulsar
from pulsar.apps.wsgi import Router
from pulsar.apps.wsgi.handlers import WsgiHandler
from pulsar.apps.wsgi import WSGIServer, WsgiResponse

blueprint = Router('/')


@blueprint.router('sync', methods=['get', 'post'])
def sync_case(request):
    return WsgiResponse(200, 'sync')


@blueprint.router('async', methods=['delete', 'put'])
async def async_cast(request):
    return WsgiResponse(200, 'async')


def server(**kwargs):
    return WSGIServer(callable=WsgiHandler((blueprint, )), **kwargs)


if __name__ == '__main__':  # pragma    nocover
    server().start()