summaryrefslogtreecommitdiffstats
path: root/base/server
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2015-08-16 19:00:00 +0200
committerChristian Heimes <cheimes@redhat.com>2015-08-17 21:14:12 +0200
commit74a355185eeb30e7d42ff2d29c4c3c3c298b2a12 (patch)
tree06d46c066aa64b7004ad2f4409fb58c83541b419 /base/server
parentc46caa19d9e1fb429fd77693abcca2fe668366aa (diff)
downloadpki-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')
-rw-r--r--base/server/python/pki/server/__init__.py5
-rw-r--r--base/server/python/pki/server/cli/migrate.py7
-rw-r--r--base/server/python/pki/server/cli/nuxwdog.py10
-rw-r--r--base/server/python/pki/server/deployment/pkihelper.py5
-rwxr-xr-xbase/server/upgrade/10.0.1/01-ReplaceRandomNumberGenerator12
-rwxr-xr-xbase/server/upgrade/10.0.5/01-EnableSessionInAuthenticator4
-rwxr-xr-xbase/server/upgrade/10.1.99/05-RemoveConfigPathFromWebXML4
-rwxr-xr-xbase/server/upgrade/10.2.1/01-AddTLSRangeSupport4
-rwxr-xr-xbase/server/upgrade/10.2.2/01-MoveWebApplicationDeploymentLocations4
-rwxr-xr-xbase/server/upgrade/10.2.2/02-EnableWebApplicationAutoDeploy4
10 files changed, 32 insertions, 27 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(
diff --git a/base/server/upgrade/10.0.1/01-ReplaceRandomNumberGenerator b/base/server/upgrade/10.0.1/01-ReplaceRandomNumberGenerator
index 11b379465..a17a27d70 100755
--- a/base/server/upgrade/10.0.1/01-ReplaceRandomNumberGenerator
+++ b/base/server/upgrade/10.0.1/01-ReplaceRandomNumberGenerator
@@ -66,8 +66,8 @@ class ReplaceRandomNumberGenerator(
self.remove_authenticator(document)
self.remove_realm(document)
- with open(context_xml, 'w') as f:
- f.write(etree.tostring(document, pretty_print=True))
+ with open(context_xml, 'wb') as f:
+ document.write(f, pretty_print=True, encoding='utf-8')
def upgrade_instance(self, instance):
@@ -97,8 +97,8 @@ class ReplaceRandomNumberGenerator(
self.add_manager(document)
- with open(context_xml, 'w') as f:
- f.write(etree.tostring(document, pretty_print=True))
+ with open(context_xml, 'wb') as f:
+ document.write(f, pretty_print=True, encoding='utf-8')
def update_pki_context_xml(self, instance):
@@ -123,8 +123,8 @@ class ReplaceRandomNumberGenerator(
self.add_manager(document)
- with open(context_xml, 'w') as f:
- f.write(etree.tostring(document, pretty_print=True))
+ with open(context_xml, 'wb') as f:
+ document.write(f, pretty_print=True, encoding='utf-8')
def create_meta_inf(self, instance, path):
diff --git a/base/server/upgrade/10.0.5/01-EnableSessionInAuthenticator b/base/server/upgrade/10.0.5/01-EnableSessionInAuthenticator
index 36b22697b..a4e836d24 100755
--- a/base/server/upgrade/10.0.5/01-EnableSessionInAuthenticator
+++ b/base/server/upgrade/10.0.5/01-EnableSessionInAuthenticator
@@ -44,8 +44,8 @@ class EnableSessionInAuthenticator(
self.enable_session(document)
- with open(context_xml, 'w') as f:
- f.write(etree.tostring(document, pretty_print=True))
+ with open(context_xml, 'wb') as f:
+ document.write(f, pretty_print=True, encoding='utf-8')
def enable_session(self, document):
diff --git a/base/server/upgrade/10.1.99/05-RemoveConfigPathFromWebXML b/base/server/upgrade/10.1.99/05-RemoveConfigPathFromWebXML
index 3e1d47e2e..42a4127c5 100755
--- a/base/server/upgrade/10.1.99/05-RemoveConfigPathFromWebXML
+++ b/base/server/upgrade/10.1.99/05-RemoveConfigPathFromWebXML
@@ -54,8 +54,8 @@ class RemoveConfigPathFromWebXML(pki.server.upgrade.PKIServerUpgradeScriptlet):
document = etree.parse(web_xml)
self.remove_config_path(document, default_cs_cfg)
- with open(web_xml, 'w') as f:
- f.write(etree.tostring(document, pretty_print=True))
+ with open(web_xml, 'wb') as f:
+ document.write(f, pretty_print=True, encoding='utf-8')
def remove_config_path(self, document, default_cs_cfg):
diff --git a/base/server/upgrade/10.2.1/01-AddTLSRangeSupport b/base/server/upgrade/10.2.1/01-AddTLSRangeSupport
index 4a3997fce..db27d015c 100755
--- a/base/server/upgrade/10.2.1/01-AddTLSRangeSupport
+++ b/base/server/upgrade/10.2.1/01-AddTLSRangeSupport
@@ -47,8 +47,8 @@ class AddTLSRangeSupport(pki.server.upgrade.PKIServerUpgradeScriptlet):
# Once all changes are made, write the XML back into the same server.xml
# This way we're preserving any other customization that has been done
# to the server.xml
- with open(server_xml, 'w') as f:
- f.write(etree.tostring(document, pretty_print=True))
+ with open(server_xml, 'wb') as f:
+ document.write(f, pretty_print=True, encoding='utf-8')
def add_tls_range(self, document):
diff --git a/base/server/upgrade/10.2.2/01-MoveWebApplicationDeploymentLocations b/base/server/upgrade/10.2.2/01-MoveWebApplicationDeploymentLocations
index 313ee0d71..d83372de1 100755
--- a/base/server/upgrade/10.2.2/01-MoveWebApplicationDeploymentLocations
+++ b/base/server/upgrade/10.2.2/01-MoveWebApplicationDeploymentLocations
@@ -128,5 +128,5 @@ class MoveWebApplicationDeploymentLocations(
context.set('docBase', new_webapp)
- with open(context_xml, 'w') as f:
- f.write(etree.tostring(document, pretty_print=True))
+ with open(context_xml, 'wb') as f:
+ document.write(f, pretty_print=True, encoding='utf-8')
diff --git a/base/server/upgrade/10.2.2/02-EnableWebApplicationAutoDeploy b/base/server/upgrade/10.2.2/02-EnableWebApplicationAutoDeploy
index ffa94d81c..04b6a6fda 100755
--- a/base/server/upgrade/10.2.2/02-EnableWebApplicationAutoDeploy
+++ b/base/server/upgrade/10.2.2/02-EnableWebApplicationAutoDeploy
@@ -49,5 +49,5 @@ class EnableWebApplicationAutoDeploy(
for host in hosts:
host.set('autoDeploy', 'true')
- with open(server_xml, 'w') as f:
- f.write(etree.tostring(document, pretty_print=True))
+ with open(server_xml, 'wb') as f:
+ document.write(f, pretty_print=True, encoding='utf-8')