Ejemplo n.º 1
0
 def prepare_exception(self, exc, serializer=None):
     """Prepare exception for serialization."""
     serializer = self.serializer if serializer is None else serializer
     if serializer in EXCEPTION_ABLE_CODECS:
         return get_pickleable_exception(exc)
     return {'exc_type': type(exc).__name__,
             'exc_message': ensure_serializable(exc.args, self.encode),
             'exc_module': type(exc).__module__}
Ejemplo n.º 2
0
 def prepare_exception(self, exc, serializer=None):
     """Prepare exception for serialization."""
     serializer = self.serializer if serializer is None else serializer
     if serializer in EXCEPTION_ABLE_CODECS:
         return get_pickleable_exception(exc)
     return {'exc_type': type(exc).__name__,
             'exc_message': ensure_serializable(exc.args, self.encode),
             'exc_module': type(exc).__module__}
Ejemplo n.º 3
0
 def test_json_exception_arguments(self):
     self.b.serializer = 'json'
     x = self.b.prepare_exception(Exception(object))
     assert x == {
         'exc_message': serialization.ensure_serializable(
             (object,), self.b.encode),
         'exc_type': Exception.__name__,
         'exc_module': Exception.__module__}
     y = self.b.exception_to_python(x)
     assert isinstance(y, Exception)
Ejemplo n.º 4
0
 def test_json_exception_arguments(self):
     self.b.serializer = 'json'
     x = self.b.prepare_exception(Exception(object))
     assert x == {
         'exc_message': serialization.ensure_serializable(
             (object,), self.b.encode),
         'exc_type': Exception.__name__,
         'exc_module': Exception.__module__}
     y = self.b.exception_to_python(x)
     assert isinstance(y, Exception)
Ejemplo n.º 5
0
 def prepare_exception(self, exc, serializer=None):
     """Prepare exception for serialization."""
     serializer = self.serializer if serializer is None else serializer
     if serializer in EXCEPTION_ABLE_CODECS:
         return get_pickleable_exception(exc)
     exctype = type(exc)
     return {
         "exc_type": getattr(exctype, "__qualname__", exctype.__name__),
         "exc_message": ensure_serializable(exc.args, self.encode),
         "exc_module": exctype.__module__,
     }
Ejemplo n.º 6
0
 def test_pickle(self):
     assert (1, object) == \
         ensure_serializable((1, object), encoder=pickle.dumps)
Ejemplo n.º 7
0
 def test_json_py2(self):
     assert (1, "<type 'object'>") == \
         ensure_serializable([1, object], encoder=json.dumps)
Ejemplo n.º 8
0
 def test_pickle(self):
     expected = (1, object)
     actual = ensure_serializable(expected, encoder=pickle.dumps)
     assert expected == actual
Ejemplo n.º 9
0
 def test_json_py2(self):
     expected = (1, "<type 'object'>")
     actual = ensure_serializable([1, object], encoder=json.dumps)
     assert expected == actual
Ejemplo n.º 10
0
 def test_pickle(self):
     expected = (1, object)
     actual = ensure_serializable(expected, encoder=pickle.dumps)
     assert expected == actual
Ejemplo n.º 11
0
 def test_json_py2(self):
     expected = (1, "<type 'object'>")
     actual = ensure_serializable([1, object], encoder=json.dumps)
     assert expected == actual