serializer: Fail if dictionary uses invalid keys
authorMichael Hanselmann <hansmi@google.com>
Fri, 23 Sep 2011 14:26:10 +0000 (16:26 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 23 Sep 2011 14:39:34 +0000 (16:39 +0200)
commitfd0351aef246f5d36e641209429e2ec093d325f8
tree71c5672da6175b5fca840da35e02a75dfd461757
parent9869e771704ada62bab001e729c52a36525ef081
serializer: Fail if dictionary uses invalid keys

JSON only supports a very restricted set of types for dictionary keys,
among them strings, booleans and “null”. Integers and floats are
converted to strings. Since this can cause a lot of confusion in Python,
this check raises an exception if a caller tries to use such types.

Since the pre-Python 2.6 “simplejson” module doesn't support overriding
the function where the conversion takes place this check can only be
done for the newer “json” module.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: René Nussbaumer <rn@google.com>
lib/serializer.py
test/ganeti.serializer_unittest.py