kua
kua copied to clipboard
feature/typed_var
This feature was described in comments of #2
- Adds var validators
- Adds support for I10L URLs, mostly coz validating on a encoded string does not make much sense
- Adds support for clashing URLs
- Breaking change: on clashing URLs first added URL will match. Previous to this last added URL would had match.
Usage:
is_num = lambda part: part.isdigit()
routes.add('api/user/:id', {'GET': my_get_controller}, {'id': is_num})
route = routes.match('api/user/123')
route.params
# {'id': '123'}
route = routes.match('api/user/bad')
# Raises RouteError
Coverage decreased (-0.7%) to 99.322% when pulling 8b09e79394d355c8df06878b76310a317594db6f on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
Coverage remained the same at 100.0% when pulling a029c16c0c86bc7035f0ff81cccd53025b1ff280 on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
Coverage remained the same at 100.0% when pulling cce066776e0bbeac4f3ca421fbea023c8368c3de on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
Leaving this open since it has some missing functionality (the pattern matching). To fix that it's basically a matter of changing the _Route
tree end into a list of routes and going through them until one matches.
Nice move!
I'd personally decouplate route and validation, as per API, so something like:
routes = Routes()
routes.validate(int=my_in_validator, foobar=my_foobar_validator)
routes.add('/test/int:id/foobar:param')
Coverage decreased (-1.6%) to 98.382% when pulling 7737dbe2cae890f273a0d4071fdaf6250233291a on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
Coverage decreased (-1.6%) to 98.382% when pulling ea93dacc0967bab00fc412eaa18c99d12397cb06 on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
Coverage decreased (-0.6%) to 99.369% when pulling d5e0860cdd311089e99d220cde87820a7b7ea530 on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
@yohanboniface yeah, I was planning on supporting both cases but I think I'll support just the one you suggested.
Coverage decreased (-0.6%) to 99.381% when pulling cbf3ff3d0e062d77bbfdfbb3ff4cef8d60cc8d49 on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
Coverage decreased (-0.6%) to 99.394% when pulling fc605894a51930d8b9e4f5b4c782295fcd415bdc on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
Coverage decreased (-0.6%) to 99.398% when pulling 82d626c8462ca689c0ab8e17a26d4b38c16eac50 on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
Coverage decreased (-0.6%) to 99.398% when pulling 82d626c8462ca689c0ab8e17a26d4b38c16eac50 on feature/var_validate into 178dbb3db22ae38f504c2a9a5b525749da91fbea on master.
Just curious ... what is the status of this? Is this project dead?
It's completed (since inception). I may or may not add ~~bloat~~ new features to it. This PR was not merged 'cause I never made my mind about #7