1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00
samba-mirror/python/samba/gp_parse/__init__.py
Garming Sam 7047f457dc gp_parse: Introduce new module for parsing GPO files
This is the default parser which will cause the file to be restored
as-is -- leaving only an effectively blank XML file as a placeholder.

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-16 23:42:20 +02:00

58 lines
2.0 KiB
Python

# GPO Parser for generic extensions
#
# Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
# Written by Garming Sam <garming@catalyst.net.nz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from xml.dom import minidom
from io import BytesIO
from xml.etree.ElementTree import ElementTree
class GPNoParserException(Exception):
pass
# [MS-GPIPSEC] (LDAP)
# [MS-GPDPC] Deployed Printer Connections (LDAP)
# [MS-GPPREF] Preferences Extension (XML)
# [MS-GPWL] Wireless/Wired Protocol Extension (LDAP)
class GPParser(object):
encoding = 'utf-16'
output_encoding = 'utf-8'
def parse(self, contents):
pass
def write_xml(self, filename):
with file(filename, 'w') as f:
f.write('<?xml version="1.0" encoding="utf-8"?><UnknownFile/>')
def load_xml(self, filename):
pass
def write_binary(self, filename):
raise GPNoParserException("This file has no parser available.")
def write_pretty_xml(self, xml_element, handle):
# Add the xml header as well as format it nicely.
# ElementTree doesn't have a pretty-print, so use minidom.
et = ElementTree(xml_element)
temporary_bytes = BytesIO()
et.write(temporary_bytes, encoding=self.output_encoding,
xml_declaration=True)
minidom_parsed = minidom.parseString(temporary_bytes.getvalue())
handle.write(minidom_parsed.toprettyxml(encoding=self.output_encoding))