diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-02-12 06:55:38 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-02-12 07:10:31 +0100 |
commit | 21ac6ff143cc8bebfbd1818af28e8c6f82cd5265 (patch) | |
tree | a61fe8976bb0253d567db8621f3cb7de6d378aa2 /tools/xml_helper.py | |
parent | pager: support SYSTEMD_LESS environment variable (diff) | |
download | systemd-21ac6ff143cc8bebfbd1818af28e8c6f82cd5265.tar.xz systemd-21ac6ff143cc8bebfbd1818af28e8c6f82cd5265.zip |
man: use xinclude to de-deduplicate common text
I only tested with python-lxml. I'm not sure if xml.etree should be
deprecated.
Diffstat (limited to 'tools/xml_helper.py')
-rw-r--r-- | tools/xml_helper.py | 22 |
1 files changed, 13 insertions, 9 deletions
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 <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) +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 |