summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins/Cfg.py
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-04-26 15:18:04 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-04-26 15:18:04 -0500
commitbef2d0c73eb0b3fd071f616aa43a945ae2d103b7 (patch)
tree6b7442075da3d88d649ac9cbe82d6007558e7c8f /src/lib/Server/Plugins/Cfg.py
parent944df5470f9d30717baccf7b716fd4847b31da27 (diff)
downloadbcfg2-bef2d0c73eb0b3fd071f616aa43a945ae2d103b7.tar.gz
bcfg2-bef2d0c73eb0b3fd071f616aa43a945ae2d103b7.tar.bz2
bcfg2-bef2d0c73eb0b3fd071f616aa43a945ae2d103b7.zip
Plugins: Add full PY3K compatibility
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src/lib/Server/Plugins/Cfg.py')
-rw-r--r--src/lib/Server/Plugins/Cfg.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/lib/Server/Plugins/Cfg.py b/src/lib/Server/Plugins/Cfg.py
index 6c7a40a52..41cf6c9c1 100644
--- a/src/lib/Server/Plugins/Cfg.py
+++ b/src/lib/Server/Plugins/Cfg.py
@@ -6,6 +6,7 @@ import logging
import lxml
import os
import re
+import sys
import tempfile
import Bcfg2.Server.Plugin
@@ -21,6 +22,13 @@ except:
logger = logging.getLogger('Bcfg2.Plugins.Cfg')
+def u_str(string, encoding):
+ if sys.hexversion >= 0x03000000:
+ return str(string, encoding)
+ else:
+ return unicode(string, encoding)
+
+
# snipped from TGenshi
def removecomment(stream):
"""A genshi filter that removes comments from the stream."""
@@ -131,7 +139,8 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet):
data = stream.render('text')
if data == '':
entry.set('empty', 'true')
- except Exception, e:
+ except Exception:
+ e = sys.exc_info()[1]
logger.error("Cfg: genshi exception: %s" % e)
raise Bcfg2.Server.Plugin.PluginExecutionError
else:
@@ -145,8 +154,9 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet):
entry.text = binascii.b2a_base64(data)
else:
try:
- entry.text = unicode(data, self.encoding)
- except UnicodeDecodeError, e:
+ entry.text = u_str(data, self.encoding)
+ except UnicodeDecodeError:
+ e = sys.exc_info()[1]
logger.error("Failed to decode %s: %s" % (entry.get('name'), e))
logger.error("Please verify you are using the proper encoding.")
raise Bcfg2.Server.Plugin.PluginExecutionError