Skip to content
This repository has been archived by the owner on Mar 8, 2018. It is now read-only.

Problem with non-ascii attributes #7

Open
phdru opened this issue Apr 14, 2011 · 1 comment
Open

Problem with non-ascii attributes #7

phdru opened this issue Apr 14, 2011 · 1 comment

Comments

@phdru
Copy link

phdru commented Apr 14, 2011

Hi! First I got the problem with Cheetah 2.4.2 in Debian 6.0, but it seems latest Cheetah 2.4.4 has the same bug (if it's a bug and not an error on my side). I narrowed the problem to the following code in Compiler.py, line 1476:

def attributes(self):
    attribs = [self.setting('indentationStep') + str(attrib)
                  for attrib in self._generatedAttribs ]
    return '\n\n'.join(attribs)

The problem is in str(attrib) - if attrib is non-ascii unicode (I don't know how Cheetah works but it seems it converts the entire source to unicode) then str(attrib) fails. I cannot even compile the following simple template:

#encoding utf-8
#attr $test = 'тест' # this is 'test' in Russian

See:

$ cheetah compile test.tmpl
Compiling test.tmpl -> test.py
Traceback (most recent call last):
        ...
      File "/usr/lib/pymodules/python2.6/Cheetah/Compiler.py", line 1478, in attributes for attrib in self._generatedAttribs ]
UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-11: ordinal not in range(128)
@phdru
Copy link
Author

phdru commented Apr 14, 2011

Instead of str(attrib) there should be something like

if isinstance(attrib, unicode):
    value = attrib.encode(template_encoding)
else:
    value = str(attrib)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant