diff options
author | Christian Heimes <cheimes@redhat.com> | 2015-08-16 19:00:00 +0200 |
---|---|---|
committer | Christian Heimes <cheimes@redhat.com> | 2015-08-17 21:14:12 +0200 |
commit | 74a355185eeb30e7d42ff2d29c4c3c3c298b2a12 (patch) | |
tree | 06d46c066aa64b7004ad2f4409fb58c83541b419 /base/server/python | |
parent | c46caa19d9e1fb429fd77693abcca2fe668366aa (diff) | |
download | pki-74a355185eeb30e7d42ff2d29c4c3c3c298b2a12.tar.gz pki-74a355185eeb30e7d42ff2d29c4c3c3c298b2a12.tar.xz pki-74a355185eeb30e7d42ff2d29c4c3c3c298b2a12.zip |
Py3 compatibility: write XML as encoded bytes
Python 3 treats serialized XML as encoded bytes. etree must encode XML
to UTF-8 and write it to a file opened in binary mode.
Diffstat (limited to 'base/server/python')
-rw-r--r-- | base/server/python/pki/server/__init__.py | 5 | ||||
-rw-r--r-- | base/server/python/pki/server/cli/migrate.py | 7 | ||||
-rw-r--r-- | base/server/python/pki/server/cli/nuxwdog.py | 10 | ||||
-rw-r--r-- | base/server/python/pki/server/deployment/pkihelper.py | 5 |
4 files changed, 16 insertions, 11 deletions
diff --git a/base/server/python/pki/server/__init__.py b/base/server/python/pki/server/__init__.py index 2f5fb461f..97b2e9799 100644 --- a/base/server/python/pki/server/__init__.py +++ b/base/server/python/pki/server/__init__.py @@ -215,8 +215,9 @@ class PKIInstance(object): context.set('docBase', doc_base) # write deployment descriptor - with open(context_xml, 'w') as f: - f.write(etree.tostring(document, pretty_print=True)) + with open(context_xml, 'wb') as f: + # xml as UTF-8 encoded bytes + document.write(f, pretty_print=True, encoding='utf-8') # set deployment descriptor ownership and permission os.chown(context_xml, self.uid, self.gid) diff --git a/base/server/python/pki/server/cli/migrate.py b/base/server/python/pki/server/cli/migrate.py index 98330eff4..ba5e63116 100644 --- a/base/server/python/pki/server/cli/migrate.py +++ b/base/server/python/pki/server/cli/migrate.py @@ -132,8 +132,9 @@ class MigrateCLI(pki.cli.CLI): self.print_help() sys.exit(1) - with open(filename, 'w') as f: - f.write(etree.tostring(document, pretty_print=True)) + with open(filename, 'wb') as f: + # xml as UTF-8 encoded bytes + document.write(f, pretty_print=True, encoding='utf-8') def migrate_server_xml_to_tomcat7(self, document): server = document.getroot() @@ -395,7 +396,7 @@ class MigrateCLI(pki.cli.CLI): sys.exit(1) with open(filename, 'w') as f: - f.write(etree.tostring(document, pretty_print=True)) + document.write(f, pretty_print=True, encoding='utf-8') def migrate_context_xml_to_tomcat7(self, document): context = document.getroot() diff --git a/base/server/python/pki/server/cli/nuxwdog.py b/base/server/python/pki/server/cli/nuxwdog.py index bdcc18a00..dd54f5683 100644 --- a/base/server/python/pki/server/cli/nuxwdog.py +++ b/base/server/python/pki/server/cli/nuxwdog.py @@ -211,8 +211,9 @@ class NuxwdogEnableCLI(pki.cli.CLI): connector.set('passwordClass', self.nuxwdog_pwstore_class) connector.set('passwordFile', conf_file) - with open(filename, 'w') as f: - f.write(etree.tostring(document, pretty_print=True)) + with open(filename, 'wb') as f: + # xml as UTF-8 encoded bytes + document.write(f, pretty_print=True, encoding='utf-8') os.chown(filename, instance.uid, instance.gid) @@ -366,8 +367,9 @@ class NuxwdogDisableCLI(pki.cli.CLI): connector.set('passwordClass', self.plain_pwstore_class) connector.set('passwordFile', pw_conf) - with open(filename, 'w') as f: - f.write(etree.tostring(document, pretty_print=True)) + with open(filename, 'wb') as f: + # xml as UTF-8 encoded bytes + document.write(f, pretty_print=True, encoding='utf-8') os.chown(filename, instance.uid, instance.gid) diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py index e6833d270..35e218a7b 100644 --- a/base/server/python/pki/server/deployment/pkihelper.py +++ b/base/server/python/pki/server/deployment/pkihelper.py @@ -4599,8 +4599,9 @@ class PKIDeployer: context = document.getroot() context.set('docBase', doc_base) - with open(new_descriptor, 'w') as f: - f.write(etree.tostring(document, pretty_print=True)) + with open(new_descriptor, 'wb') as f: + # xml as UTF-8 encoded bytes + document.write(f, pretty_print=True, encoding='utf-8') os.chown(new_descriptor, self.mdict['pki_uid'], self.mdict['pki_gid']) os.chmod( |