I can’t give you the perfect solution, but you can try to use string.Template. You either pre-process your incoming URL and then use string.Template directly, e.g.
In [6]: url="http://api.app.com/{foo}"
In [7]: up=string.Template(re.sub("{", "${", url))
In [8]: up.substitute({"foo":"bar"})
Out[8]: 'http://api.app.com/bar'
using the default syntax $ {...} for substitute identifiers. Or you are a subclass string.Templateto manage an identifier pattern like
class MyTemplate(string.Template):
delimiter = ...
pattern = ...
but I did not understand this.
source
share