Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sqlalchemy-bot opened this issue Mar 6, 2007 · 2 comments
Closed

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

sqlalchemy-bot opened this issue Mar 6, 2007 · 2 comments
Labels
bug Something isn't working compiler low priority

Comments

@sqlalchemy-bot
Copy link

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)
@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

yes, added the proper escaping in [changeset:230], thanks.

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler low priority
Projects
None yet
Development

No branches or pull requests

1 participant