diff options
author | Sol Jerome <solj@ices.utexas.edu> | 2010-08-05 21:33:52 +0000 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2010-08-05 16:33:58 -0500 |
commit | 0c366586f5037f2f91ac0452fc47936ddb9716e3 (patch) | |
tree | c0499e502948c162478e9c89d7cd0eaffc3133a8 /src | |
parent | 5536c3d4017ccc4177821904316fe67b909efe72 (diff) | |
download | bcfg2-0c366586f5037f2f91ac0452fc47936ddb9716e3.tar.gz bcfg2-0c366586f5037f2f91ac0452fc47936ddb9716e3.tar.bz2 bcfg2-0c366586f5037f2f91ac0452fc47936ddb9716e3.zip |
TGenshi/TCheetah: Add base64 encoding support for files handled by non-Cfg plugins
Reported by Chris Brinker in IRC. We should now have the ability to use
encoding=base64 in info/info.xml files for paths that are handled by the
TGenshi and TCheetah plugins. I think this common code for the three
plugins can be merged once we implement Kisielk's idea for having a
single Cfg/TGenshi/TCheetah tree.
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@6002 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Server/Plugins/TCheetah.py | 7 | ||||
-rw-r--r-- | src/lib/Server/Plugins/TGenshi.py | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/lib/Server/Plugins/TCheetah.py b/src/lib/Server/Plugins/TCheetah.py index 91c830620..d40f4baf3 100644 --- a/src/lib/Server/Plugins/TCheetah.py +++ b/src/lib/Server/Plugins/TCheetah.py @@ -1,6 +1,7 @@ '''This module implements a templating generator based on Cheetah''' __revision__ = '$Revision$' +import binascii import logging import sys import traceback @@ -54,7 +55,11 @@ class TemplateFile: if type(self.template) == unicode: entry.text = self.template else: - entry.text = unicode(str(self.template), self.encoding) + if entry.get('encoding') == 'base64': + # take care of case where file needs base64 encoding + entry.text = binascii.b2a_base64(self.template) + else: + entry.text = unicode(str(self.template), self.encoding) except: (a, b, c) = sys.exc_info() msg = traceback.format_exception(a, b, c, limit=2)[-1][:-1] diff --git a/src/lib/Server/Plugins/TGenshi.py b/src/lib/Server/Plugins/TGenshi.py index 4bc8338c9..29e6d7307 100644 --- a/src/lib/Server/Plugins/TGenshi.py +++ b/src/lib/Server/Plugins/TGenshi.py @@ -1,6 +1,7 @@ """This module implements a templating generator based on Genshi.""" __revision__ = '$Revision$' +import binascii import logging import Bcfg2.Server.Plugin @@ -90,7 +91,11 @@ class TemplateFile: if type(textdata) == unicode: entry.text = textdata else: - entry.text = unicode(textdata, self.encoding) + if entry.get('encoding') == 'base64': + # take care of case where file needs base64 encoding + entry.text = binascii.b2a_base64(textdata) + else: + entry.text = unicode(textdata, self.encoding) else: try: xmldata = stream.render('xml', strip_whitespace=False) |