From f07a3b301a6d55055e4c617e6ff32b39ae3e3842 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 15 Jun 2015 10:01:43 +0530 Subject: [PATCH] Do not generate optional path components if they are not specified in url_for() --- src/calibre/srv/routes.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/calibre/srv/routes.py b/src/calibre/srv/routes.py index de2b2d0882..d587bef49d 100644 --- a/src/calibre/srv/routes.py +++ b/src/calibre/srv/routes.py @@ -143,15 +143,13 @@ class Route(object): not_spec = self.required_names - frozenset(kwargs) if not_spec: raise RouteError('The required variable(s) %s were not specified for the route: %s' % (','.join(not_spec), self.endpoint.route)) - args = self.defaults.copy() - args.update(kwargs) def quoted(x): if not isinstance(x, unicode) and not isinstance(x, bytes): x = unicode(x) if isinstance(x, unicode): x = x.encode('utf-8') return urlquote(x, '') - args = {k:quoted(v) for k, v in args.iteritems()} + args = {k:quoted(v) for k, v in kwargs.iteritems()} route = self.var_pat.sub(lambda m:'{%s}' % m.group(1).partition('=')[0].lstrip('+'), self.endpoint.route) return route.format(**args)