Edgewall Software

Ticket #125: unicode_input_for_text_template-r611.diff

File unicode_input_for_text_template-r611.diff, 1.3 KB (added by cboos, 10 years ago)

Proposed fix

  • genshi/template/tests/text.py

     
    5454        tmpl = TextTemplate(text, encoding='iso-8859-1')
    5555        self.assertEqual(u'x\xf6y', unicode(tmpl.generate(foo='x', bar='y')))
    5656
     57    def test_unicode_input(self):
     58        text = u'$foo\xf6$bar'
     59        tmpl = TextTemplate(text)
     60        self.assertEqual(u'x\xf6y', unicode(tmpl.generate(foo='x', bar='y')))
     61
    5762    def test_empty_lines1(self):
    5863        tmpl = TextTemplate("""Your items:
    5964
  • genshi/template/text.py

     
    6464        stream = [] # list of events of the "compiled" template
    6565        dirmap = {} # temporary mapping of directives to elements
    6666        depth = 0
    67         if not encoding:
    68             encoding = 'utf-8'
    6967
    70         source = source.read().decode(encoding, 'replace')
     68        source = source.read()
     69        if isinstance(source, str):
     70            source = source.decode(encoding or 'utf-8', 'replace')
    7171        offset = 0
    7272        lineno = 1
    7373