summaryrefslogtreecommitdiff
path: root/tools/xml_helper.py
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-02-12 00:55:38 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-02-12 01:10:31 -0500
commit21ac6ff143cc8bebfbd1818af28e8c6f82cd5265 (patch)
treea61fe8976bb0253d567db8621f3cb7de6d378aa2 /tools/xml_helper.py
parentf366d58dc1fe51b300167446597750d29687c3c5 (diff)
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.py22
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