Beispiel #1
0
    def connect(cls,
                app,
                *paths,
                methods=None,
                name=None,
                router=None,
                view=None):
        """ Connect to the application. """
        if isinstance(cls.app, DummyApp):
            cls.app, dummy = app, cls.app
            dummy.install(app, cls)

        @coroutine
        def handler(request):
            return cls().dispatch(request, view=view)

        if not paths:
            paths = ["/%s" % cls.__name__]

        routes_register(app,
                        handler,
                        *paths,
                        methods=methods,
                        router=router,
                        name=name or cls.name)
Beispiel #2
0
def test_register_url(app):
    from muffin.urls import routes_register

    def handler():
        pass

    routes_register(app, handler, '/path/{id:\d+}', '/path/add', '/other/path', name='endpoint')

    assert 'endpoint' in app.router and app.router['endpoint'].url(id=5) == '/path/5'
    assert 'endpoint2' in app.router and app.router['endpoint2'].url() == '/path/add'
    assert 'endpoint3' in app.router and app.router['endpoint3'].url() == '/other/path'
Beispiel #3
0
    def connect(cls, app, *paths, methods=None, name=None, router=None, view=None):
        """ Connect to the application. """
        if isinstance(cls.app, DummyApp):
            cls.app, dummy = app, cls.app
            dummy.install(app, cls)

        @coroutine
        def handler(request):
            return cls().dispatch(request, view=view)

        if not paths:
            paths = ["/%s" % cls.__name__]

        routes_register(
            app, handler, *paths, methods=methods, router=router, name=name or cls.name)
Beispiel #4
0
    def bind(cls,
             app,
             *paths,
             methods=None,
             name=None,
             router=None,
             view=None):
        """Bind to the given application."""
        cls.app = app
        if cls.app is not None:
            for _, m in inspect.getmembers(cls, predicate=inspect.isfunction):
                if not hasattr(m, ROUTE_PARAMS_ATTR):
                    continue
                paths_, methods_, name_ = getattr(m, ROUTE_PARAMS_ATTR)
                name_ = name_ or ("%s.%s" % (cls.name, m.__name__))
                delattr(m, ROUTE_PARAMS_ATTR)
                cls.app.register(*paths_,
                                 methods=methods_,
                                 name=name_,
                                 handler=cls)(m)

        @coroutine
        @functools.wraps(cls)
        def handler(request):
            return cls().dispatch(request, view=view)

        if not paths:
            paths = ["/%s" % cls.__name__]

        return routes_register(app,
                               handler,
                               *paths,
                               methods=methods,
                               router=router,
                               name=name or cls.name)
Beispiel #5
0
def test_register_url(app):
    from muffin.urls import routes_register

    def handler():
        pass

    routes_register(app,
                    handler,
                    r'/path/{id:\d+}',
                    '/path/add',
                    '/other/path',
                    name='endpoint')

    assert 'endpoint' in app.router and str(
        app.router['endpoint'].url_for(id=5)) == '/path/5'
    assert 'endpoint2' in app.router and str(
        app.router['endpoint2'].url_for()) == '/path/add'
    assert 'endpoint3' in app.router and str(
        app.router['endpoint3'].url_for()) == '/other/path'
Beispiel #6
0
    def connect(cls, app, *paths, methods=None, name=None, router=None, view=None):
        """Connect to the given application."""
        cls.app = app

        if cls.app is not None:
            for _, m in inspect.getmembers(cls, predicate=inspect.isfunction):
                if not hasattr(m, ROUTE_PARAMS_ATTR):
                    continue
                paths_, methods_, name_ = getattr(m, ROUTE_PARAMS_ATTR)
                delattr(m, ROUTE_PARAMS_ATTR)
                cls.app.register(*paths_, methods=methods_, name=name_, handler=cls)(m)

        @coroutine
        def handler(request):
            return cls().dispatch(request, view=view)

        if not paths:
            paths = ["/%s" % cls.__name__]

        return routes_register(
            app, handler, *paths, methods=methods, router=router, name=name or cls.name)