From 0f8d403d1a86cfbfe8222662dc445e16e8f7eff9 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 21 Nov 2013 13:03:04 -0500 Subject: Bundler: Fix parsing XML template output with encoding declaration lxml 3.2.1 complains when you try to parse a unicode (in Python 2) or string (in Python 3) containing an XML document with an encoding declaration. Traceback: ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration. This encodes the document as a string (in Python 2) or bytes (in Python 3) to avoid the lxml error. There may be other places this happens, too, although in most other cases we should use lxml.etree.parse() to parse a file, or we parse strings (in Python 2) instead of unicode objects. --- src/lib/Bcfg2/Server/Plugins/Bundler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/Bcfg2/Server/Plugins/Bundler.py b/src/lib/Bcfg2/Server/Plugins/Bundler.py index fb327f7ef..58f8f4430 100644 --- a/src/lib/Bcfg2/Server/Plugins/Bundler.py +++ b/src/lib/Bcfg2/Server/Plugins/Bundler.py @@ -53,9 +53,9 @@ if HAS_GENSHI: stream = self.template.generate( metadata=metadata, repo=SETUP['repo']).filter(removecomment) - data = lxml.etree.XML(stream.render('xml', - strip_whitespace=False), - parser=Bcfg2.Server.XMLParser) + data = lxml.etree.XML( + stream.render('xml', strip_whitespace=False).encode(), + parser=Bcfg2.Server.XMLParser) bundlename = os.path.splitext(os.path.basename(self.name))[0] bundle = lxml.etree.Element('Bundle', name=bundlename) for item in self.Match(metadata, data): -- cgit v1.2.3-1-g7c22