Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #588 (closed defect: fixed)

Opened 13 years ago

Last modified 9 years ago

TurboCheetah blows up with non-ASCII values

Reported by: sluggoster@… Owned by: Chris Arndt
Priority: normal Milestone: 1.0.x bugfix
Component: unassigned Version:
Severity: major Keywords:


If you take a Cheetah template and give it a dictionary containing non-ASCII unicode values, TurboCheetah? raises this lovely exception:

  File "/usr/local/lib/python2.4/TurboGears-0.9a0dev_r787-py2.4.egg/turbogears/view.py", line 60, in render
    return engine.render(info, format, fragment, template)
  File "/usr/local/lib/python2.4/TurboCheetah-0.9.3-py2.4.egg/turbocheetah/cheetahsupport.py", line 73, in render
    return str(tempobj)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa5' in position 43239: ordinal not in range(128)

Although str() will happily handle 8-bit strings ("\0xa5"), it refuses to work with unicode characters of the same value ("\uxa5").

To fix, and to make TurboCheetah? do the same thing as TurboKid?, append this line to TurboCheetah?.init:

      self.defaultencoding = options.get("cheetah.encoding", "utf-8")

Then replace "return str(tempobj)" in TurboCheetah?.render with:

      return unicode(tempobj).encode(self.defaultencoding)

Remember to document 'cheetah.encoding' in the default config file.

This deserves wider testing because I got it to work for me but I got some random errors while debugging it with different data, so I'm not 100% sure it will always work for everybody. But the current situation does not work at all.

Change History

comment:1 Changed 13 years ago by jorge.vargas

  • Component changed from CherryPy to unassigned
  • Milestone changed from 0.9 to 1.0

comment:2 Changed 12 years ago by alberto

  • Milestone changed from 1.0 to 1.1

comment:3 Changed 12 years ago by alberto

  • Milestone changed from 1.1 to __unclassified__

Batch moved into unclassified from 1.1 to properly track progress on the later

comment:4 Changed 12 years ago by Chris Arndt

  • Owner changed from anonymous to Chris Arndt

Assigning this to me, since I have to test it for my own apps anyway.

comment:5 Changed 12 years ago by chrisz

  • Status changed from new to closed
  • Resolution set to fixed

I have solved this differently in TurboCheetah? 1.0, as suggested in the Pylons Cookbook ( http://wiki.pylonshq.com/display/pylonscookbook/Cheetah+templates). We may still want to add a cheetah.encoding option, though. If anybody thinks this is useful, please reopen the ticket or make a new one.

comment:6 Changed 12 years ago by chrisz

Just noticed that cheetah.encoding should already work by default thanks to the turbogears.util.get_template_encoding_default() function.

comment:7 Changed 9 years ago by chrisz

  • Milestone changed from __unclassified__ to 1.0.x bugfix
Note: See TracTickets for help on using tickets.