[sysadmin-bin] convert sets into lists when saving json
- From: Olav Vitters <ovitters src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] convert sets into lists when saving json
- Date: Tue, 20 Jan 2015 21:00:25 +0000 (UTC)
commit 49153c9eed51a33314567a40a4b4358d5948f14a
Author: Olav Vitters <olav vitters nl>
Date: Tue Jan 20 22:00:21 2015 +0100
convert sets into lists when saving json
ftpadmin | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/ftpadmin b/ftpadmin
index ee41307..f94c88e 100755
--- a/ftpadmin
+++ b/ftpadmin
@@ -255,6 +255,13 @@ if not hasattr(tarfile.TarFile, 'xzopen'):
tarfile.open = XzTarFile.open
+class SetEncoder(json.JSONEncoder):
+ def default(self, obj):
+ if isinstance(obj, set):
+ return list(obj)
+ return json.JSONEncoder.default(self, obj)
+
+
class BasicInfo(object):
GROUPID = None
@@ -440,7 +447,7 @@ class DOAP(BasicInfo):
if os.path.exists(self.jsonfile):
os.remove(self.jsonfile)
with open(self.jsonfile, 'w') as f:
- json.dump((self.JSONVERSION, self.etag, self.last_modified, self.info, self.tarball_to_module,
self.uid_to_module), f)
+ json.dump((self.JSONVERSION, self.etag, self.last_modified, self.info, self.tarball_to_module,
self.uid_to_module), f, cls=SetEncoder)
if self.GROUPID is not None:
os.fchown(f.fileno(), -1, self.GROUPID)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]