How to use the blacksheep.server.routing.Route function in blacksheep

To help you get started, we’ve selected a few blacksheep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_identity_binder_by_param_name_user():

    async def handler(user):
        ...

    binders = get_binders(Route(b'/', handler), {})

    assert isinstance(binders[0], IdentityBinder)
github RobertoPrevato / BlackSheep / tests / test_router.py View on Github external
def test_route_bad_matches(pattern, url):
    route = Route(pattern, mock_handler)
    match = route.match(url)

    assert match is None
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_parameters_get_binders_from_services_by_type():

    def handler(a: str, b: int, c: Cat):
        ...

    binders = get_binders(Route(b'/', handler), {
        str: object(),
        int: object(),
        Cat: object()
    })

    assert all(isinstance(binder, FromServices) for binder in binders)
    assert binders[0].expected_type is str
    assert binders[1].expected_type is int
    assert binders[2].expected_type is Cat
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_identity_binder_by_param_type(annotation_type):
    async def handler(param):
        ...

    handler.__annotations__['param'] = annotation_type

    binders = get_binders(Route(b'/', handler), {})

    assert isinstance(binders[0], IdentityBinder)
github RobertoPrevato / BlackSheep / tests / test_normalization.py View on Github external
def test_parameters_get_binders_from_route():

    def handler(a, b, c):
        ...

    binders = get_binders(Route(b'/:a/:b/:c', handler), {})

    assert all(isinstance(binder, FromRoute) for binder in binders)
    assert binders[0].name == 'a'
    assert binders[1].name == 'b'
    assert binders[2].name == 'c'
github RobertoPrevato / BlackSheep / blacksheep / server / files / static.py View on Github external
def get_routes_for_static_files(source_folder, extensions, discovery, cache_max_age, frozen):
    for file_paths in get_files_to_serve(source_folder, extensions, discovery):
        full_path = file_paths.get('full_path')

        if file_paths.get('is_dir'):
            handler = get_folder_getter(full_path, cache_max_age)
        else:
            handler = get_frozen_file_getter(full_path, cache_max_age) \
                if frozen else get_file_getter(full_path, cache_max_age)
        yield Route(quote(file_paths.get('rel_path')).encode(), handler)
github RobertoPrevato / BlackSheep / blacksheep / server / routing.py View on Github external
def add(self, method: str, pattern: BytesOrStr, handler: Any):
        self.mark_handler(handler)
        method = ensure_bytes(method)
        pattern = ensure_bytes(pattern)
        new_route = Route(pattern, handler)
        self._check_duplicate(method, new_route)
        self.add_route(method, new_route)