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

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

Expand Messages
  • Sandro Dentella
    I lost the battle.... or I m lost, as you prefere... Trying to debug a UnicodeEncodeError I wote these lines. Just a n makes the difference between a smooth
    Message 1 of 4 , Mar 1, 2007
    View Source
    • 0 Attachment
      I lost the battle.... or I'm lost, as you prefere...


      Trying to debug a UnicodeEncodeError I wote 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)
      sandro@bluff:~/src/django/jungle/template$ e cheetah-test2.py


      Thanks

      sandro*:-)


      --
      Sandro Dentella *:-)
      http://www.tksql.org TkSQL Home page - My GPL work

      -------------------------------------------------------------------------
      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
    • Sandro Dentella
      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
      Message 2 of 4 , Mar 8, 2007
      View Source
      • 0 Attachment
        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
      • Mike Orr
        ... It looks like a bug in the compiler. Running in pdb and upacking the list comprehension, str(self._finishedMethods()[1]) is raising UnicodeDecodeError.
        Message 3 of 4 , Mar 8, 2007
        View Source
        • 0 Attachment
          On 3/8/07, Sandro Dentella <sandro@...> 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

          It looks like a bug in the compiler. Running in pdb and upacking the
          list comprehension, "str(self._finishedMethods()[1])" is raising
          UnicodeDecodeError. .__str__ on the instance does the same thing, and
          .__unicode__ doesn't exist. The class is too complicated for me to
          analyze further so you'll have to wait till Tavis can look at it.

          Adding a fourth \n didn't help. Nor did removing the '$'. But this works:

          tmpl = unicode('\n\n\nCiao $a ù', 'latin-1')

          --
          Mike Orr <sluggoster@...>

          -------------------------------------------------------------------------
          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
        • Tavis Rudd
          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
          Message 4 of 4 , Mar 28, 2007
          View Source
          • 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
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.