I'm not entirely clear what you're describing, usually a template doesn't have very many literal Python strings at all. Such literals are usually coming from the calling application. Within the template, you wouldn't usually be saying "${u'some string'}", you'd be saying, "some string".
If you are actually doing something like ${u'some string'}, if 'some string' is all ASCII then you can omit the 'u'.
> --
> You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
> To post to this group, send email to mako-d...@googlegroups.com.
> To unsubscribe from this group, send email to mako-discuss...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mako-discuss?hl=en.
>
> An example would be just:
> Mako template: ${apiCall1()}, $(apiCall2()}
> resulting in an
> output file: Text1, u'Text2'
then that's coming from your apiCall2() function.
>
> The function apiCall2() always returns an Unicode string.
If that is exactly what you see, then this is not the full story. It's returning a unicode string that *contains* the characters "u''", such as:
"u'Text2'"
Here is an example:
from mako.template import Template
t = Template("""
${apiCall1()}, ${apiCall2()}
""")
def apiCall1():
return "Text1"
def apiCall2():
return "u'Text2'"
print t.render(apiCall1=apiCall1, apiCall2=apiCall2)
that's the only way to get that exact effect. Or if apiCall2() returns an object with a __str__() method that resolves to it's repr(). The issue lies within apiCall2() likely calling repr() on a string value instead of str().
> I have
> neither control over the rendering settings nor the apiCall2()
> internals.
It would appear apiCall2's output is pretty wrong, but you'd need to filter apiCall2's output:
from mako.template import Template
import re
t = Template("""
${apiCall1()}, ${apiCall2() | unRepr}
""")
def apiCall1():
return "Text1"
def apiCall2():
return "u'Text2'"
def unRepr(value):
return re.sub(r"u'(.*?)'", lambda m:m.group(1), value)
print t.render(apiCall1=apiCall1, apiCall2=apiCall2, unRepr=unRepr)