-
-
Save solj/b5dd55f6453da0134b49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------ genshi-utf8.py -------------------- | |
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import genshi.core | |
from genshi.template import TemplateLoader, NewTextTemplate | |
class mdata(object): | |
def __init__(self): | |
self.Probes = {'test': 'группы'} | |
m = mdata() | |
loader = TemplateLoader(max_cache_size=0) | |
template = loader.load('/var/lib/bcfg2/Cfg/test.txt/test.txt.genshi', | |
cls=NewTextTemplate, | |
encoding='utf-8') | |
stream = template.generate(name='/test.txt', | |
metadata=m, | |
path='/var/lib/bcfg2/Cfg/test.txt/test.txt.genshi', | |
source_path='/var/lib/bcfg2/Cfg/test.txt/test.txt.genshi', | |
repo='/var/lib/bcfg2', | |
encoding='utf-8') | |
print(stream.render('text', encoding='utf-8')) | |
------------------ test.txt.genshi -------------------- | |
${metadata.Probes['test']} | |
# python genshi-utf8.py | |
Traceback (most recent call last): | |
File "genshi-utf8.py", line 22, in <module> | |
print(stream.render('text', encoding='utf-8')) | |
File "/usr/lib64/python2.7/site-packages/genshi/core.py", line 184, in render | |
return encode(generator, method=method, encoding=encoding, out=out) | |
File "/usr/lib64/python2.7/site-packages/genshi/output.py", line 57, in encode | |
return _encode(''.join(list(iterator))) | |
File "/usr/lib64/python2.7/site-packages/genshi/output.py", line 582, in __call__ | |
yield unicode(data) | |
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment