Mercurial supports nested quoting contexts:
ohnobinki@gibby ~/dcx-ridik-variable-substitution $ t="{'a{'b{pad('x', 2, ',', True)}'}'}"; echo "${t}"; hg log -l1 --template "${t}"; echo
{'a{'b{pad('x', 2, ',', True)}'}'}
ab,x
It also supports “weirdly quoted strings”, as I call them: