Esempio n. 1
0
 def test_loads(self):
     for expected, value in self.get_loads_test_values():
         result = hipack.loads(six.b(dedent(value)))
         self.assertTrue(isinstance(result, dict))
         self.assertDictEqual(expected, result)
         # Passing Unicode text should work as well.
         result = hipack.loads(dedent(value))
         self.assertTrue(isinstance(result, dict))
         self.assertDictEqual(expected, result)
Esempio n. 2
0
    def from_hipack(cls, data, encoding=None):
        """
        Deserializes an object from HiPack and validates it.

        Loads data from a HiPack string, decoding it with `hipack.loads()`,
        and the resulting value is passed to a `.validate()` class method.
        That method is responsible of validating the input date, and
        optionally returning an object which represents the deserialized
        data.
        """
        from hipack import loads
        return cls.validate(loads(data))
Esempio n. 3
0
 def test_parse_valid_message_with_annots(self, text):
     def check_annot(annotations, text, value):
         self.assertIn(u"annot", annotations)
         return value
     value = hipack.loads(six.b(text), check_annot)
     self.assertIsInstance(value, dict)