Edgewall Software

Ticket #6932: r6692.patch

File r6692.patch, 1.1 KB (added by trac-ja@…, 4 years ago)

Patch against source:trunk@6692

  • trac/util/__init__.py

     
    152152            lbound = max(0, lineno - context) 
    153153            ubound = lineno + 1 + context 
    154154 
    155             before = [l.rstrip('\n') for l in lines[lbound:lineno]] 
    156             line = lines[lineno].rstrip('\n') 
    157             after = [l.rstrip('\n') for l in lines[lineno + 1:ubound]] 
    158155 
     156            charset = None 
     157            rep = re.compile('coding[=:]\s*([-\w.]+)') 
     158            for linestr in lines[0], lines[1]: 
     159                match = rep.search(linestr) 
     160                if match: 
     161                    charset = match.group(1) 
     162                    break 
     163 
     164            before = [to_unicode(l.rstrip('\n'), charset) 
     165                         for l in lines[lbound:lineno]] 
     166            line = to_unicode(lines[lineno].rstrip('\n'), charset) 
     167            after = [to_unicode(l.rstrip('\n'), charset) \ 
     168                         for l in lines[lineno + 1:ubound]] 
     169 
    159170            return before, line, after 
    160171        finally: 
    161172            fileobj.close()