Edgewall Software

Opened 16 years ago

Closed 13 years ago

#262 closed defect (wontfix)

UnicodeDecodeError when accessing missing dictionary item

Reported by: blackhex@… Owned by: cmlenz
Priority: minor Milestone: 0.6.1
Component: Template processing Version: 0.5.1
Keywords: unicode dictionary Cc:

Description

Accessing dictionary items with key containing non-ASCII characters fails with UnicodeDecodeError? exception when that item is not present in the dictionary.

For example:

MarkupTemplate(u"<p>${foo['öäü']}</p>").generate(foo={u'öäü': 42}).render('xhtml')

goes well, but

MarkupTemplate(u"<p>${foo['ö']}</p>").generate(foo={u'öäü': 42}).render('xhtml')

throws exception.

Change History (4)

comment:1 Changed 15 years ago by cmlenz

  • Milestone changed from 0.6 to 0.6.1

comment:2 Changed 15 years ago by Carsten Klein <carsten.klein@…>

I do not think that this is a bug in genshi.

See http://www.velocityreviews.com/forums/t598507-getattr-setattr-still-ascii-only-not-unicode-blows-up-sgmllibfrom-beautifulsoup.html

for more information.

Excerpt:

Identifiers are restricted -- see section 2.3 (Identifiers and
keywords
) of the Reference Manual. The restriction is in effect that
they match r'[A-Za-z_][A-Za-z0-9_]*\Z'. Hence if you can't use
obj.nonASCIIname in your code, it makes sense for the equivalent usage
in setattr and getattr not to be available.

The same holds true for keys in a dict.

comment:3 Changed 15 years ago by Carsten Klein <carsten.klein@…>

I think that the first example which is working is a nice side effect and nothing that should be counted on. Please use ascii only identifiers for keys.

comment:4 Changed 13 years ago by hodgestar

  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.