This is a masterpiece, but maybe there's a simpler way? As I understand it, the triply-quoted mako stuff is because the underscore syntax collides with the mako syntax, both want to interpret `<%`, is that right?  There's got to be a clearer way to accomplish this.