Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Problem with non-ascii attributes #7

Open
phdru opened this Issue · 1 comment

1 participant

@phdru

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

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 join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.