From 65c6d6d86c71c0dcb1edb9a313d6a417c2d4cf26 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 11 Oct 2015 12:47:44 +0530 Subject: [PATCH] Allow passing None to url_for() to get the url_prefix --- src/calibre/srv/routes.py | 2 ++ src/calibre/srv/tests/routes.py | 1 + 2 files changed, 3 insertions(+) diff --git a/src/calibre/srv/routes.py b/src/calibre/srv/routes.py index 4e381b163c..ce77f19000 100644 --- a/src/calibre/srv/routes.py +++ b/src/calibre/srv/routes.py @@ -290,5 +290,7 @@ class Router(object): return ans def url_for(self, route, **kwargs): + if route is None: + return self.url_prefix or '/' route = getattr(route, 'route_key', route) return self.url_prefix + self.routes[route].url_for(**kwargs) diff --git a/src/calibre/srv/tests/routes.py b/src/calibre/srv/tests/routes.py index 722cb929ff..8f50f10d95 100644 --- a/src/calibre/srv/tests/routes.py +++ b/src/calibre/srv/tests/routes.py @@ -97,3 +97,4 @@ class TestRouter(BaseTest): self.ae(ep, soak_opt), self.ae(args, ['a/b']) self.ae(router.url_for('/needs quoting', x='a/b c'), '/needs quoting/a%2Fb%20c') + self.ae(router.url_for(None), '/')