From 21ac6ff143cc8bebfbd1818af28e8c6f82cd5265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 12 Feb 2014 00:55:38 -0500 Subject: man: use xinclude to de-deduplicate common text I only tested with python-lxml. I'm not sure if xml.etree should be deprecated. --- tools/xml_helper.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'tools') diff --git a/tools/xml_helper.py b/tools/xml_helper.py index 08e226fa21..0d91a17bbc 100644 --- a/tools/xml_helper.py +++ b/tools/xml_helper.py @@ -17,19 +17,23 @@ # You should have received a copy of the GNU Lesser General Public License # along with systemd; If not, see . -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) +try: _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') + 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') + except ImportError: import xml.etree.ElementTree as tree import re as _re -- cgit v1.2.3