summaryrefslogtreecommitdiffstats
path: root/base/common/python/pki/encoder.py
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2013-03-18 11:29:52 -0400
committerAde Lee <alee@redhat.com>2013-03-21 12:11:31 -0400
commitc9a081037aa5bf15cf6226f06ea54ea98deba5bc (patch)
treeba095458c940b4db7923719ce6cf6e14a2c1da8e /base/common/python/pki/encoder.py
parent22d50cc526c7fd4224a4d5a0ae9ebf66afd8e83a (diff)
downloadpki-c9a081037aa5bf15cf6226f06ea54ea98deba5bc.tar.gz
pki-c9a081037aa5bf15cf6226f06ea54ea98deba5bc.tar.xz
pki-c9a081037aa5bf15cf6226f06ea54ea98deba5bc.zip
Refactor installation code to remove dependency on jython
Connection is now made to the installation servlet through a python client using JSON. The code to construct the ConfgurationRequest and parse the results has been moved to pkihelper.py, and configuration.py no longer calls a separate jython process to create the Configuration object and parse the results. The jython code has therefore been removed. Also added status servlet to other java subsystems, to be tested prior to starting configuration. Trac Ticket 532
Diffstat (limited to 'base/common/python/pki/encoder.py')
-rw-r--r--base/common/python/pki/encoder.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/base/common/python/pki/encoder.py b/base/common/python/pki/encoder.py
new file mode 100644
index 000000000..7fee57e71
--- /dev/null
+++ b/base/common/python/pki/encoder.py
@@ -0,0 +1,31 @@
+import json
+import pki.system
+
+TYPES = {}
+NOTYPES = {}
+
+class CustomTypeEncoder(json.JSONEncoder):
+ """A custom JSONEncoder class that knows how to encode core custom
+ objects.
+
+ Custom objects are encoded as JSON object literals (ie, dicts) with
+ one key, 'TypeName' where 'TypeName' is the actual name of the
+ type to which the object belongs. That single key maps to another
+ object literal which is just the __dict__ of the object encoded."""
+
+ def default(self, obj):
+ for k, v in TYPES.items():
+ if isinstance(obj, v):
+ return { k: obj.__dict__ }
+ for k, v in NOTYPES.items():
+ if isinstance(obj, v):
+ return obj.__dict__
+ return json.JSONEncoder.default(self, obj)
+
+
+def CustomTypeDecoder(dct):
+ if len(dct) == 1:
+ type_name, value = dct.items()[0]
+ if type_name in TYPES:
+ return TYPES[type_name].from_dict(value)
+ return dct