Loading ...
Sorry, an error occurred while loading the content.

3986Re: [Cheetahtemplate-discuss] unicode: I lost...

Expand Messages
  • Sandro Dentella
    Mar 8, 2007
      Hi all,

      I'm still stuck with this problem. Since the following code is *really
      simple*, can sombody tell me if:

      1. I'm doing something the wrong way
      2. This code doen *not* raise error to you
      3. This is a bug (of cheetah?)
      4. there is a workaround


      Previous message:

      I lost the battle.... or I'm lost, as you prefere...
      Trying to debug a UnicodeEncodeError I wrote these lines. Just a '\n' makes
      the difference between a smooth compile and a UnicodeEncodeError.

      Do you have any explanation?

      # coding: latin-1
      from Cheetah.Template import Template

      tmpl = unicode('\n\nCiao ù $a', 'latin-1') ### works
      #tmpl = unicode('\n\n\nCiao ù $a', 'latin-1') ### doesn't compile!

      context = {'a': u'lettera A \xf9', }
      t = Template.compile(tmpl)
      ret = t(namespaces=[context])
      print ret.respond().encode('latin-1')

      This is the traceback:

      Traceback (most recent call last):
      File "cheetah-test2.py", line 7, in ?
      t = Template.compile(tmpl)
      File "/var/lib/python-support/python2.4/Cheetah/Template.py", line 716, in compile
      generatedModuleCode = compiler.getModuleCode()
      File "/var/lib/python-support/python2.4/Cheetah/Compiler.py", line 1849, in getModuleCode
      return self.wrapModuleDef()
      File "/var/lib/python-support/python2.4/Cheetah/Compiler.py", line 1867, in wrapModuleDef
      moduleDef = """%(header)s
      File "/var/lib/python-support/python2.4/Cheetah/Compiler.py", line 1951, in classDefs
      classDefs = [str(klass) for klass in self._finishedClasses() ]
      File "/var/lib/python-support/python2.4/Cheetah/Compiler.py", line 1422, in classDef
      return self.wrapClassDef()
      File "/var/lib/python-support/python2.4/Cheetah/Compiler.py", line 1446, in wrapClassDef
      File "/var/lib/python-support/python2.4/Cheetah/Compiler.py", line 1432, in addMethods
      File "/var/lib/python-support/python2.4/Cheetah/Compiler.py", line 1471, in methodDefs
      methodDefs = [str(methGen) for methGen in self._finishedMethods() ]
      UnicodeEncodeError: 'ascii' codec can't encode character u'\xf9' in position 655: ordinal not in range(128)

      Take Surveys. Earn Cash. Influence the Future of IT
      Join SourceForge.net's Techsay panel and you'll get the chance to share your
      opinions on IT & business topics through brief surveys-and earn cash
      Cheetahtemplate-discuss mailing list
    • Show all 4 messages in this topic