Skip to content

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

Description

@sqlalchemy-bot

Migrated issue, originally created by Anonymous

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions