1. Michael Bayer
  2. mako

Issues

Issue #24 resolved

<%def> and <%call> with unicode string as argument

guest
created an issue

Can't use u"unicode strings" as arguments in <%def> and <%call> tags. Tested with SVN revision 224.

-*- coding: utf-8 -*- <%def name="bello(foo, bar)"> <b>Foo:</b> ${ foo }<br> <b>Bar:</b> ${ bar }<br> </%def> <%call expr="bello(foo=u'árvíztűrő tükörfúrógép', bar=u'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP'"> </%call>

will raise

Traceback (most recent call last): File "wsgiref/handlers.py", line 92, in run File "/usr/local/myapp/lib/myapp/wsgiapp.py", line 87, in application template = templatelookup.get_template(templateuri) File "/usr/local/myapp/lib/mako/lookup.py", line 68, in get_template return self.load(srcfile, uri) File "/usr/local/myapp/lib/mako/lookup.py", line 110, in load self.collection[uri] = Template(uri=uri, filename=posixpath.normpath(filename), lookup=self, module_filename=(self.modulename_callable is not None and self.modulename_callable(filename, uri) or None), self.template_args) File "/usr/local/myapp/lib/mako/template.py", line 68, in init _compile_module_file(self, file(filename).read(), filename, path) File "/usr/local/myapp/lib/mako/template.py", line 186, in _compile_module_file node = Lexer(text, filename, input_encoding=template.input_encoding, preprocessor=template.preprocessor).parse() File "/usr/local/myapp/lib/mako/lexer.py", line 138, in parse if self.match_tag_start(): File "/usr/local/myapp/lib/mako/lexer.py", line 188, in match_tag_start self.append_node(parsetree.Tag, keyword, attributes) File "/usr/local/myapp/lib/mako/lexer.py", line 83, in append_node node = nodecls(*args, kwargs) File "/usr/local/myapp/lib/mako/parsetree.py", line 149, in call return type.call(cls, keyword, attributes, kwargs) File "/usr/local/myapp/lib/mako/parsetree.py", line 262, in init self.code = ast.PythonCode(attributes['expr'], self.lineno, self.pos, self.filename) File "/usr/local/myapp/lib/mako/ast.py", line 39, in init expr = parse(code.lstrip(), "exec", lineno, pos, filename) File "/usr/local/myapp/lib/mako/ast.py", line 17, in parse return compiler_parse(code, mode) File "compiler/transformer.py", line 52, in parse File "compiler/transformer.py", line 129, in parsesuite UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 12: ordinal not in range(128)

and

-*- coding: utf-8 -*- <%def name="hello(foo=u'árvíztűrő tükörfúrógép', bar=u'ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP')"> <b>Foo:</b> ${ foo }<br> <b>Bar:</b> ${ bar }<br> </%def> ${ hello() }

will raise

Traceback (most recent call last): File "wsgiref/handlers.py", line 92, in run File "/usr/local/myapp/lib/myapp/wsgiapp.py", line 87, in application template = templatelookup.get_template(templateuri) File "/usr/local/myapp/lib/mako/lookup.py", line 68, in get_template return self.load(srcfile, uri) File "/usr/local/myapp/lib/mako/lookup.py", line 110, in load self.collection[uri] = Template(uri=uri, filename=posixpath.normpath(filename), lookup=self, module_filename=(self.modulename_callable is not None and self.modulename_callable(filename, uri) or None), self.template_args) File "/usr/local/myapp/lib/mako/template.py", line 68, in init _compile_module_file(self, file(filename).read(), filename, path) File "/usr/local/myapp/lib/mako/template.py", line 186, in _compile_module_file node = Lexer(text, filename, input_encoding=template.input_encoding, preprocessor=template.preprocessor).parse() File "/usr/local/myapp/lib/mako/lexer.py", line 138, in parse if self.match_tag_start(): File "/usr/local/myapp/lib/mako/lexer.py", line 188, in match_tag_start self.append_node(parsetree.Tag, keyword, attributes) File "/usr/local/myapp/lib/mako/lexer.py", line 83, in append_node node = nodecls(*args, kwargs) File "/usr/local/myapp/lib/mako/parsetree.py", line 149, in call return type.call(cls, keyword, attributes, kwargs) File "/usr/local/myapp/lib/mako/parsetree.py", line 247, in init self.function_decl = ast.FunctionDecl("def " + name + ":pass", self.lineno, self.pos, self.filename) File "/usr/local/myapp/lib/mako/ast.py", line 166, in init expr = parse(code, "exec", lineno, pos, filename) File "/usr/local/myapp/lib/mako/ast.py", line 17, in parse return compiler_parse(code, mode) File "compiler/transformer.py", line 52, in parse File "compiler/transformer.py", line 129, in parsesuite UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 16: ordinal not in range(128)

Comments (1)

  1. Log in to comment