From: Noel Power Date: Wed, 5 Sep 2018 11:36:00 +0000 (+0100) Subject: python/samba/gp_parse: PY2/PY3 compat changes for __init__.py X-Git-Tag: tdb-1.3.17~930 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0934fc14ef6ed94a100caa8a622b370d41bc1182;p=thirdparty%2Fsamba.git python/samba/gp_parse: PY2/PY3 compat changes for __init__.py Fixes. 1) sorting of xml.etree.ElementTree.Element, in PY2 sort seems to sort lists of these. In PY3 this no longer works. Choosing tag as the sort key for py3 so at least in python3 there is a consistent sort (probably won't match how it is sorted in PY2 but nothing seems to depend on that) 2) md5 requires bytes 3) tostring returns bytes in PY3, adjust code for that Signed-off-by: Noel Power Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/gp_parse/__init__.py b/python/samba/gp_parse/__init__.py index 80fbee68ed4..911f7df3e7d 100644 --- a/python/samba/gp_parse/__init__.py +++ b/python/samba/gp_parse/__init__.py @@ -21,6 +21,7 @@ from xml.dom import minidom from io import BytesIO from xml.etree.ElementTree import ElementTree, fromstring, tostring from hashlib import md5 +from samba.compat import get_bytes ENTITY_USER_ID = 0 @@ -81,7 +82,7 @@ class GPParser(object): handle.write(minidom_parsed.toprettyxml(encoding=self.output_encoding)) def new_xml_entity(self, name, ent_type): - identifier = md5(name).hexdigest() + identifier = md5(get_bytes(name)).hexdigest() type_str = entity_type_to_string(ent_type) @@ -99,7 +100,7 @@ class GPParser(object): # Locate all user_id and all ACLs user_ids = root.findall('.//*[@user_id="TRUE"]') - user_ids.sort() + user_ids.sort(key = lambda x: x.tag) for elem in user_ids: old_text = elem.text @@ -117,7 +118,7 @@ class GPParser(object): global_entities.update([(old_text, elem.text)]) acls = root.findall('.//*[@acl="TRUE"]') - acls.sort() + acls.sort(key = lambda x: x.tag) for elem in acls: old_text = elem.text @@ -136,7 +137,7 @@ class GPParser(object): global_entities.update([(old_text, elem.text)]) share_paths = root.findall('.//*[@network_path="TRUE"]') - share_paths.sort() + share_paths.sort(key = lambda x: x.tag) for elem in share_paths: old_text = elem.text @@ -171,7 +172,8 @@ class GPParser(object): output_xml = tostring(root) for ent in entities: - output_xml = output_xml.replace(ent[0].replace('&', '&'), ent[0]) + entb = get_bytes(ent[0]) + output_xml = output_xml.replace(entb.replace(b'&', b'&'), entb) with open(out_file, 'wb') as f: f.write(output_xml)