1. Michael Bayer
  2. mako

Issues

Issue #99 resolved

new <%namespace:defname> syntax doesn't handle multibyte chars

Michael Bayer
repo owner created an issue
  1. coding: utf-8 from mako.template import Template

t = Template("""# coding: utf-8

<%def name="my_def(x)"> x is: ${x} </%def>

old way ${my_def(u'drôle de petit voix m’a réveillé')}

new way <%self:my_def x='drôle de petit voix m’a réveillé'/>

workaround <%self:my_def x="${u'drôle de petit voix m’a réveillé'}"/>

""")

print t.render_unicode().encode('utf-8')

Comments (5)

  1. guest

    The patch attached fixed the problem for me. Several lexer related unit tests fail after the patch though, but they seem to test for a specific internal state, which is affected by this patch so it doesn't necessarily mean anything.

  2. Michael Bayer reporter

    the patch does not fix:

    1. coding: utf-8

    from mako.template import Template

    t = Template("""# coding:utf-8 <%def name="test(value)"> ${value} </%def> øæå <%self:test value="øæå" /> ${self.test(value=u"øæå")} """) print t.render_unicode().encode('utf-8')

    the output is incorrect.

  3. Michael Bayer reporter

    attached is a patch that actually works with file/module- based templates as well as python 2.4. I still would like to attempt reducing the points at which we are aware of unicode/string/bytes in this recipe. The "native unicode" mode makes it quite difficult to achieve. While native unicode mode is obviously out the window in python 3, I'd still like to make the source have an absolute minimum of encoding touchpoints so that the Py3k procedure will be very smooth.

  4. Log in to comment