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

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

Expand Messages
  • Tavis Rudd
    Mar 28, 2007
    • 0 Attachment
      Hi Sandro,
      Sorry for not replying earlier. I've been very busy with some client work
      so far this year and haven't had time to keep up with the Cheetah list
      emails until now.

      The bug you found is related to the way Cheetah pretty-prints the python
      code it generates. I've just fixed it in the cvs repository and will be
      cutting a new release soon.

      Tavis

      On Thu, 8 Mar 2007, Sandro Dentella wrote:

      > 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
      >
      >
      > Thanks
      > sandro
      >
      > 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
      > addMethods()
      > File "/var/lib/python-support/python2.4/Cheetah/Compiler.py", line 1432, in addMethods
      > classDefChunks.extend([
      > 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
      > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
      > _______________________________________________
      > Cheetahtemplate-discuss mailing list
      > Cheetahtemplate-discuss@...
      > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      >
    • Show all 4 messages in this topic