Exemple #1
0
 def __setstate__(self, dct):
     self._exception_str = dct['exception_str']
     if 'exc_args' in dct:
         self._exc_args = tuple(dct['exc_args'])
     else:
         # Guess we got an older version somehow, before this
         # was added, so at that point just set to an empty tuple...
         self._exc_args = ()
     self._traceback_str = dct['traceback_str']
     self._exc_type_names = dct['exc_type_names']
     if 'exc_info' in dct:
         # Tracebacks can't be serialized/deserialized, but since we
         # provide a traceback string (and more) this should be
         # acceptable...
         #
         # TODO(harlowja): in the future we could do something like
         # what the twisted people have done, see for example
         # twisted-13.0.0/twisted/python/failure.py#L89 for how they
         # created a fake traceback object...
         self._exc_info = tuple(iter_utils.fill(dct['exc_info'], 3))
     else:
         self._exc_info = None
     causes = dct.get('causes')
     if causes is not None:
         causes = tuple(self.from_dict(d) for d in causes)
     self._causes = causes
 def __setstate__(self, dct):
     self._exception_str = dct['exception_str']
     if 'exc_args' in dct:
         self._exc_args = tuple(dct['exc_args'])
     else:
         # Guess we got an older version somehow, before this
         # was added, so at that point just set to an empty tuple...
         self._exc_args = ()
     self._traceback_str = dct['traceback_str']
     self._exc_type_names = dct['exc_type_names']
     if 'exc_info' in dct:
         # Tracebacks can't be serialized/deserialized, but since we
         # provide a traceback string (and more) this should be
         # acceptable...
         #
         # TODO(harlowja): in the future we could do something like
         # what the twisted people have done, see for example
         # twisted-13.0.0/twisted/python/failure.py#L89 for how they
         # created a fake traceback object...
         self._exc_info = tuple(iter_utils.fill(dct['exc_info'], 3))
     else:
         self._exc_info = None
     causes = dct.get('causes')
     if causes is not None:
         causes = tuple(self.from_dict(d) for d in causes)
     self._causes = causes
 def test_fill_empty(self):
     self.assertEqual([], list(iter_utils.fill([1, 2, 3], 0)))
 def test_fill(self):
     self.assertEqual([None, None], list(iter_utils.fill([], 2)))
     self.assertEqual((None, None), tuple(iter_utils.fill([], 2)))
 def test_fill_less_needed(self):
     self.assertEqual("ab", "".join(iter_utils.fill("abc", 2)))
 def test_fill_custom_filler(self):
     self.assertEqual("abcd",
                      "".join(iter_utils.fill("abc", 4, filler='d')))
 def test_fill_many_empty(self):
     result = list(iter_utils.fill(compat_range(0, 50), 500))
     self.assertEqual(450, sum(1 for x in result if x is None))
     self.assertEqual(50, sum(1 for x in result if x is not None))