2017-05-01 03:26:56 +03:00
#!/usr/bin/env python3
2013-03-29 22:22:27 +04:00
# -*- Mode: python; coding: utf-8; indent-tabs-mode: nil -*- */
2017-11-18 19:32:46 +03:00
# SPDX-License-Identifier: LGPL-2.1+
2013-03-29 22:22:27 +04:00
#
# This file is part of systemd.
#
# Copyright 2012-2013 Zbigniew Jędrzejewski-Szmek
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# systemd is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
2014-02-12 09:55:38 +04:00
from lxml import etree as tree
2013-03-29 22:22:27 +04:00
2014-02-12 09:55:38 +04:00
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 )
2013-03-29 22:22:27 +04:00
2014-02-12 11:58:41 +04:00
_parser = tree . XMLParser ( )
_parser . resolvers . add ( CustomResolver ( ) )
2017-11-18 19:32:46 +03:00
2014-02-12 11:58:41 +04:00
def xml_parse ( page ) :
doc = tree . parse ( page , _parser )
doc . xinclude ( )
return doc
2017-11-18 19:32:46 +03:00
2014-02-12 11:58:41 +04:00
def xml_print ( xml ) :
return tree . tostring ( xml , pretty_print = True , encoding = ' utf-8 ' )