Пример #1
0
    def default_decoder(cls, value):
        """Default decoder.

        Recursively deserialize into immutable types (
        :class:`acme.jose.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 acme.jose.util import frozendict
     self.assertEqual(self.fdict, frozendict({'x': 1, 'y': '2'}))
Пример #3
0
 def setUp(self):
     from acme.jose.util import frozendict
     self.fdict = frozendict(x=1, y='2')
 def test_default_decoder_dict_to_frozendict(self):
     from acme.jose.json_util import Field
     obj = Field.default_decoder({'x': 2})
     self.assertTrue(isinstance(obj, util.frozendict))
     self.assertEqual(obj, util.frozendict(x=2))
 def test_init_dict(self):
     from acme.jose.util import frozendict
     self.assertEqual(self.fdict, frozendict({'x': 1, 'y': '2'}))
 def setUp(self):
     from acme.jose.util import frozendict
     self.fdict = frozendict(x=1, y='2')
Пример #7
0
    def test_init_dict(self):
        from acme.jose.util import frozendict

        self.assertEqual(self.fdict, frozendict({"x": 1, "y": "2"}))