From d59c274547b6aecb3bcbfb99d1b874d403c51bea Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 22 Aug 2012 10:00:38 -0400 Subject: fixed lxml.etree.tostring invocations --- src/lib/Bcfg2/Server/Admin/Bundle.py | 2 -- src/lib/Bcfg2/Server/Lint/__init__.py | 6 ++++-- src/lib/Bcfg2/Server/Plugin.py | 2 +- src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py | 4 ++-- src/lib/Bcfg2/Server/Plugins/FileProbes.py | 9 +++++---- src/lib/Bcfg2/Server/Plugins/Metadata.py | 5 +++-- src/lib/Bcfg2/Server/Plugins/Packages/__init__.py | 2 +- src/lib/Bcfg2/Server/Plugins/Probes.py | 4 ++-- src/lib/Bcfg2/Server/Plugins/Properties.py | 7 ++++--- src/lib/Bcfg2/Server/Plugins/Statistics.py | 2 +- 10 files changed, 23 insertions(+), 20 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Bcfg2/Server/Admin/Bundle.py b/src/lib/Bcfg2/Server/Admin/Bundle.py index 49e530b15..e5e4eadf3 100644 --- a/src/lib/Bcfg2/Server/Admin/Bundle.py +++ b/src/lib/Bcfg2/Server/Admin/Bundle.py @@ -71,8 +71,6 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore): print('Details for the "%s" bundle:' % \ (bundle_name[int(lineno)].split('.')[0])) tree = lxml.etree.parse(bundle_list[int(lineno)]) - #Prints bundle content - #print(lxml.etree.tostring(tree)) names = ['Action', 'Package', 'Path', 'Service'] for name in names: for node in tree.findall("//" + name): diff --git a/src/lib/Bcfg2/Server/Lint/__init__.py b/src/lib/Bcfg2/Server/Lint/__init__.py index 7ee18f924..e3b4c8ea7 100644 --- a/src/lib/Bcfg2/Server/Lint/__init__.py +++ b/src/lib/Bcfg2/Server/Lint/__init__.py @@ -90,9 +90,11 @@ class Plugin (object): if el.text and not keep_text: el.text = '...' [el.remove(c) for c in el.iterchildren()] - xml = lxml.etree.tostring(el, encoding='unicode').strip() + xml = lxml.etree.tostring(el, + xml_declaration=False).decode("UTF-8").strip() else: - xml = lxml.etree.tostring(element, encoding='unicode').strip() + xml = lxml.etree.tostring(element, + xml_declaration=False).decode("UTF-8").strip() return " line %s: %s" % (element.sourceline, xml) diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py index fa2e16c10..97892c42d 100644 --- a/src/lib/Bcfg2/Server/Plugin.py +++ b/src/lib/Bcfg2/Server/Plugin.py @@ -266,7 +266,7 @@ class ThreadedStatistics(Statistics, threading.Thread): try: pending_data.append((metadata.hostname, lxml.etree.tostring(data, - encoding='unicode'))) + xml_declaration=False).decode("UTF-8"))) except: err = sys.exc_info()[1] self.logger.warning("Dropping interaction for %s: %s" % diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py index 5b8dd24d3..4b9403320 100644 --- a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py +++ b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py @@ -386,8 +386,8 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet): [infotag.attrib.__setitem__(attr, metadata_updates[attr]) for attr in metadata_updates] ofile = open(self.path + "/info.xml", "w") - ofile.write(lxml.etree.tostring(infoxml, encoding='unicode', - pretty_print=True)) + ofile.write(lxml.etree.tostring(infoxml, xml_declaration=False, + pretty_print=True).decode('UTF-8')) ofile.close() self.debug_log("Wrote file %s" % os.path.join(self.path, "info.xml"), diff --git a/src/lib/Bcfg2/Server/Plugins/FileProbes.py b/src/lib/Bcfg2/Server/Plugins/FileProbes.py index a48524ac9..632d586e8 100644 --- a/src/lib/Bcfg2/Server/Plugins/FileProbes.py +++ b/src/lib/Bcfg2/Server/Plugins/FileProbes.py @@ -34,7 +34,7 @@ data = lxml.etree.Element("ProbedFileData", group=grp.getgrgid(stat[5])[0], perms=oct(stat[0] & 07777)) data.text = b64encode(open(path).read()) -print(lxml.etree.tostring(data, encoding="unicode")) +print(lxml.etree.tostring(data, xml_declaration=False).decode('UTF-8')) """ class FileProbes(Bcfg2.Server.Plugin.Plugin, @@ -214,9 +214,10 @@ class FileProbes(Bcfg2.Server.Plugin.Plugin, root = lxml.etree.Element("FileInfo") root.append(info) try: - open(infoxml, "w").write(lxml.etree.tostring(root, - encoding='unicode', - pretty_print=True)) + open(infoxml, + "w").write(lxml.etree.tostring(root, + xml_declaration=False, + pretty_print=True).decode('UTF-8')) except IOError: err = sys.exc_info()[1] self.logger.error("Could not write %s: %s" % (fileloc, err)) diff --git a/src/lib/Bcfg2/Server/Plugins/Metadata.py b/src/lib/Bcfg2/Server/Plugins/Metadata.py index 8f4f42c96..bc3470273 100644 --- a/src/lib/Bcfg2/Server/Plugins/Metadata.py +++ b/src/lib/Bcfg2/Server/Plugins/Metadata.py @@ -151,8 +151,9 @@ class XMLMetadataConfig(Bcfg2.Server.Plugin.XMLFileBacked): raise Bcfg2.Server.Plugin.MetadataRuntimeError(msg) # prep data dataroot = xmltree.getroot() - newcontents = lxml.etree.tostring(dataroot, pretty_print=True, - encoding='unicode') + newcontents = lxml.etree.tostring(dataroot, xml_declaration=False, + pretty_print=True).decode('UTF-8') + fd = datafile.fileno() while locked(fd) == True: diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py index 71ae6a038..d3095300a 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py @@ -178,7 +178,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin, else: self.logger.error("Packages: Malformed Package: %s" % lxml.etree.tostring(pkg, - encoding='unicode')) + xml_declaration=False).decode('UTF-8')) gpkgs = collection.get_groups(groups) for group, pkgs in gpkgs.items(): diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py index 34b5ab187..cae06b659 100644 --- a/src/lib/Bcfg2/Server/Plugins/Probes.py +++ b/src/lib/Bcfg2/Server/Plugins/Probes.py @@ -194,8 +194,8 @@ class Probes(Bcfg2.Server.Plugin.Probing, lxml.etree.SubElement(cx, "Group", name=group) try: datafile = open(os.path.join(self.data, 'probed.xml'), 'w') - datafile.write(lxml.etree.tostring(top, encoding='unicode', - pretty_print='true')) + datafile.write(lxml.etree.tostring(top, xml_declaration=False, + pretty_print='true').decode('UTF-8')) except IOError: err = sys.exc_info()[1] self.logger.error("Failed to write probed.xml: %s" % err) diff --git a/src/lib/Bcfg2/Server/Plugins/Properties.py b/src/lib/Bcfg2/Server/Plugins/Properties.py index 3405ad50c..78019933a 100644 --- a/src/lib/Bcfg2/Server/Plugins/Properties.py +++ b/src/lib/Bcfg2/Server/Plugins/Properties.py @@ -42,9 +42,10 @@ class PropertyFile(Bcfg2.Server.Plugin.StructFile): raise Bcfg2.Server.Plugin.PluginExecutionError(msg) try: - open(self.name, "wb").write(lxml.etree.tostring(self.xdata, - encoding='unicode', - pretty_print=True)) + open(self.name, + "wb").write(lxml.etree.tostring(self.xdata, + xml_declaration=False, + pretty_print=True).decode('UTF-8')) return True except IOError: err = sys.exc_info()[1] diff --git a/src/lib/Bcfg2/Server/Plugins/Statistics.py b/src/lib/Bcfg2/Server/Plugins/Statistics.py index 33b78047a..984efb76c 100644 --- a/src/lib/Bcfg2/Server/Plugins/Statistics.py +++ b/src/lib/Bcfg2/Server/Plugins/Statistics.py @@ -35,7 +35,7 @@ class StatisticsStore(object): self.logger.error("Failed to open %s for writing: %s" % (self.filename + '.new', ioerr)) else: fout.write(lxml.etree.tostring(self.element, - encoding='unicode')) + xml_declaration=False).decode('UTF-8')) fout.close() os.rename(self.filename + '.new', self.filename) self.dirty = 0 -- cgit v1.2.3-1-g7c22