mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Do not generate optional path components if they are not specified in url_for()
This commit is contained in:
parent
818d5a9070
commit
f07a3b301a
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user