Ticket #17029: pickled_signal.diff

File pickled_signal.diff, 1.8 KB (added by Dougal Matthews, 13 years ago)
  • AUTHORS

    diff --git a/AUTHORS b/AUTHORS
    index b64a627..689b2d1 100644
    a b answer newbie questions, and generally made Django that much better:  
    550550    Gasper Zejn <zejn@kiberpipa.org>
    551551    Jarek Zgoda <jarek.zgoda@gmail.com>
    552552    Cheng Zhang
     553    Dougal Matthews <dougal@dougalmatthews.com>
    553554
    554555A big THANK YOU goes to:
    555556
  • django/dispatch/dispatcher.py

    diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py
    index ed9da57..857b06f 100644
    a b class Signal(object):  
    253253        finally:
    254254            self.lock.release()
    255255
     256    def __reduce__(self):
     257        """
     258        Return a 2-tuple containing a callable and the arguements for the
     259        callable which can be used by pickle to pickle and unpickle Signal
     260        instances.
     261        """
     262        return (Signal, (self.providing_args,))
     263
    256264
    257265def receiver(signal, **kwargs):
    258266    """
  • tests/regressiontests/signals_regress/tests.py

    diff --git a/tests/regressiontests/signals_regress/tests.py b/tests/regressiontests/signals_regress/tests.py
    index 332f5d9..90917d7 100644
    a b class SignalsRegressTests(TestCase):  
    9292        self.get_signal_output(a1.save)
    9393        self.assertEqual(self.get_signal_output(setattr, b1, 'authors', [a1]), [])
    9494        self.assertEqual(self.get_signal_output(setattr, b1, 'authors', []), [])
     95
     96    def test_pickle_signal(self):
     97        """ Test that a Signal instance can be pickled."""
     98
     99        import pickle
     100        pickled_string = """cdjango.dispatch.dispatcher\nSignal\np0\n(c__builtin__
     101set\np1\n((lp2\nS'instance'\np3\naS'using'\np4\naS'raw'\np5\natp6\nRp7\ntp8\nRp9\n."""
     102
     103        result = pickle.dumps(models.signals.pre_save)
     104        self.assertEqual(pickled_string, result)
Back to Top