summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins/TGenshi.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2008-06-30 15:59:01 +0000
committerNarayan Desai <desai@mcs.anl.gov>2008-06-30 15:59:01 +0000
commite32bbfbca5233d4ad7a5bee74698d614ff0b1f24 (patch)
tree5f6b08da35732532f2b3d8761bd7f26a61ce8aab /src/lib/Server/Plugins/TGenshi.py
parent477603f8f0680f40781559ec1cee8f85c2d76913 (diff)
downloadbcfg2-e32bbfbca5233d4ad7a5bee74698d614ff0b1f24.tar.gz
bcfg2-e32bbfbca5233d4ad7a5bee74698d614ff0b1f24.tar.bz2
bcfg2-e32bbfbca5233d4ad7a5bee74698d614ff0b1f24.zip
Unicode support (from stousignant) (Resolves Ticket #549)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4731 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins/TGenshi.py')
-rw-r--r--src/lib/Server/Plugins/TGenshi.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/lib/Server/Plugins/TGenshi.py b/src/lib/Server/Plugins/TGenshi.py
index e58fb8017..16470a231 100644
--- a/src/lib/Server/Plugins/TGenshi.py
+++ b/src/lib/Server/Plugins/TGenshi.py
@@ -17,10 +17,11 @@ def removecomment(stream):
class TemplateFile:
'''Template file creates Genshi template structures for the loaded file'''
- def __init__(self, name, properties, specific):
+ def __init__(self, name, properties, specific, encoding):
self.name = name
self.properties = properties
self.specific = specific
+ self.encoding = encoding
if self.specific.all:
matchname = self.name
elif self.specific.group:
@@ -52,9 +53,19 @@ class TemplateFile:
name=fname, metadata=metadata, path=self.name,
properties=self.properties).filter(removecomment)
if isinstance(self.template, TextTemplate):
- entry.text = stream.render('text')
+ textdata = stream.render('text')
+ if type(textdata) == unicode:
+ entry.text = textdata
+ else:
+ logger.debug("Override encoding of template to %s" % self.encoding)
+ entry.text = unicode(textdata, self.encoding)
else:
- entry.text = stream.render('xml')
+ xmldata = stream.render('xml')
+ if type(xmldata) == unicode:
+ entry.text = xmldata
+ else:
+ logger.debug("Override encoding of template to %s" % self.encoding)
+ entry.text = unicode(xmldata, self.encoding)
except TemplateError, terror:
logger.error('Genshi template error: %s' % terror)
raise Bcfg2.Server.Plugin.PluginExecutionError