summaryrefslogtreecommitdiffstats
path: root/ipaclient
diff options
context:
space:
mode:
authorDavid Kupka <dkupka@redhat.com>2016-12-14 17:19:52 +0100
committerMartin Basti <mbasti@redhat.com>2017-01-05 18:30:00 +0100
commit388ed93935de56adbf1db976e9df276327c9a1e4 (patch)
tree0dcdc79c5460b1e35e00eef16419fff2c757ea71 /ipaclient
parent0ff12de338a8db32bb10e1b41f32255e7b971b6f (diff)
downloadfreeipa-388ed93935de56adbf1db976e9df276327c9a1e4.tar.gz
freeipa-388ed93935de56adbf1db976e9df276327c9a1e4.tar.xz
freeipa-388ed93935de56adbf1db976e9df276327c9a1e4.zip
schema_cache: Make handling of string compatible with python3
https://fedorahosted.org/freeipa/ticket/6559 Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'ipaclient')
-rw-r--r--ipaclient/remote_plugins/schema.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
index 02364ca69..15c03f4af 100644
--- a/ipaclient/remote_plugins/schema.py
+++ b/ipaclient/remote_plugins/schema.py
@@ -6,6 +6,7 @@ import collections
import contextlib
import errno
import fcntl
+import io
import json
import os
import sys
@@ -373,7 +374,7 @@ class Schema(object):
self._dict = {}
self._namespaces = {}
self._help = None
- self._file = six.StringIO()
+ self._file = six.BytesIO()
for ns in self.namespaces:
self._dict[ns] = {}
@@ -407,7 +408,7 @@ class Schema(object):
def _open(self, filename, mode):
path = os.path.join(self._DIR, filename)
- with open(path, mode) as f:
+ with io.open(path, mode) as f:
if mode.startswith('r'):
fcntl.flock(f, fcntl.LOCK_SH)
else:
@@ -454,7 +455,7 @@ class Schema(object):
def _read_schema(self, fingerprint):
self._file.truncate(0)
- with self._open(fingerprint, 'r') as f:
+ with self._open(fingerprint, 'rb') as f:
self._file.write(f.read())
with zipfile.ZipFile(self._file, 'r') as schema:
@@ -504,21 +505,24 @@ class Schema(object):
ns = value
for member in ns:
path = '{}/{}'.format(key, member)
- schema.writestr(path, json.dumps(ns[member]))
+ schema.writestr(path,
+ json.dumps(ns[member]).encode('utf-8'))
else:
- schema.writestr(key, json.dumps(value))
+ schema.writestr(key, json.dumps(value).encode('utf-8'))
- schema.writestr('_help',
- json.dumps(self._generate_help(self._dict)))
+ schema.writestr(
+ '_help',
+ json.dumps(self._generate_help(self._dict)).encode('utf-8')
+ )
self._file.seek(0)
- with self._open(fingerprint, 'w') as f:
+ with self._open(fingerprint, 'wb') as f:
f.truncate(0)
f.write(self._file.read())
def _read(self, path):
with zipfile.ZipFile(self._file, 'r') as zf:
- return json.loads(zf.read(path))
+ return json.loads(zf.read(path).decode('utf-8'))
def read_namespace_member(self, namespace, member):
value = self._dict[namespace][member]