chiark / gitweb /
Fix service file to match installed elogind binary location
[elogind.git] / tools / xml_helper.py
old mode 100644 (file)
new mode 100755 (executable)
index 08e226f..0088be5
@@ -1,3 +1,4 @@
+#!/usr/bin/env python3
 #  -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
 #
 #  This file is part of systemd.
 #  You should have received a copy of the GNU Lesser General Public License
 #  along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
-try:
-    from lxml import etree as tree
+from lxml import etree as tree
 
-    class CustomResolver(tree.Resolver):
-        def resolve(self, url, id, context):
-            if 'custom-entities.ent' in url:
-                return self.resolve_filename('man/custom-entities.ent', context)
+class CustomResolver(tree.Resolver):
+    def resolve(self, url, id, context):
+        if 'custom-entities.ent' in url:
+            return self.resolve_filename('man/custom-entities.ent', context)
 
-    _parser = tree.XMLParser()
-    _parser.resolvers.add(CustomResolver())
-    xml_parse = lambda page: tree.parse(page, _parser)
-    xml_print = lambda xml: tree.tostring(xml, pretty_print=True,
-                                          encoding='utf-8')
-except ImportError:
-    import xml.etree.ElementTree as tree
-    import re as _re
-    import io as _io
-
-    def xml_parse(page):
-        s = _re.sub(b'&[a-zA-Z0-9_]+;', b'', open(page, 'rb').read())
-        return tree.parse(_io.BytesIO(s))
-    xml_print = lambda xml: tree.tostring(xml, encoding='utf-8')
+_parser = tree.XMLParser()
+_parser.resolvers.add(CustomResolver())
+def xml_parse(page):
+    doc = tree.parse(page, _parser)
+    doc.xinclude()
+    return doc
+def xml_print(xml):
+    return tree.tostring(xml, pretty_print=True, encoding='utf-8')