示例#1
0
    def default_decoder(cls, value):
        """Default decoder.

        Recursively deserialize into immutable types (
        :class:`josepy.util.frozendict` instead of
        :func:`dict`, :func:`tuple` instead of :func:`list`).

        """
        # bases cases for different types returned by json.loads
        if isinstance(value, list):
            return tuple(cls.default_decoder(subvalue) for subvalue in value)
        elif isinstance(value, dict):
            return util.frozendict(
                dict((cls.default_decoder(key), cls.default_decoder(value))
                     for key, value in six.iteritems(value)))
        else:  # integer or string
            return value
示例#2
0
 def test_init_dict(self):
     from josepy.util import frozendict
     self.assertEqual(self.fdict, frozendict({'x': 1, 'y': '2'}))
示例#3
0
 def setUp(self):
     from josepy.util import frozendict
     self.fdict = frozendict(x=1, y='2')
示例#4
0
 def test_default_decoder_dict_to_frozendict(self):
     from josepy.json_util import Field
     obj = Field.default_decoder({'x': 2})
     self.assertIsInstance(obj, util.frozendict)
     self.assertEqual(obj, util.frozendict(x=2))
示例#5
0
文件: util_test.py 项目: cloudera/hue
 def test_init_dict(self):
     from josepy.util import frozendict
     self.assertEqual(self.fdict, frozendict({'x': 1, 'y': '2'}))
示例#6
0
文件: util_test.py 项目: cloudera/hue
 def setUp(self):
     from josepy.util import frozendict
     self.fdict = frozendict(x=1, y='2')