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

        Recursively deserialize into immutable types (
        :class:`letsencrypt.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 value.iteritems()))
        else:  # integer or string
            return value
Пример #2
0
    def default_decoder(cls, value):
        """Default decoder.

        Recursively deserialize into immutable types (
        :class:`letsencrypt.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 value.iteritems()))
        else:  # integer or string
            return value
Пример #3
0
 def test_default_decoder_dict_to_frozendict(self):
     from letsencrypt.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_default_decoder_dict_to_frozendict(self):
     from letsencrypt.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))
Пример #5
0
 def test_init_dict(self):
     from letsencrypt.acme.jose.util import frozendict
     self.assertEqual(self.fdict, frozendict({'x': 1, 'y': '2'}))
Пример #6
0
 def setUp(self):
     from letsencrypt.acme.jose.util import frozendict
     self.fdict = frozendict(x=1, y='2')
Пример #7
0
 def test_init_dict(self):
     from letsencrypt.acme.jose.util import frozendict
     self.assertEqual(self.fdict, frozendict({'x': 1, 'y': '2'}))
Пример #8
0
 def setUp(self):
     from letsencrypt.acme.jose.util import frozendict
     self.fdict = frozendict(x=1, y='2')