summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgweis <gerhard.weis@gmail.com>2017-07-05 04:04:21 (GMT)
committerGitHub <noreply@github.com>2017-07-05 04:04:21 (GMT)
commitf3888ca26cba70e8e2d44a817a1a7b53a33267ce (patch)
tree568dde9c23e7187cc3e4aa5fee38a6b40cba8713
parent3392d73c9d896e80640e19e81ada457b70a95e31 (diff)
parent79b8d42cc2629b53a7a696171221d7bd3a79b30c (diff)
downloadisodate-f3888ca26cba70e8e2d44a817a1a7b53a33267ce.tar.gz
Merge pull request #32 from EniramLtd/master
isodate.UTC remains the same object in a pickle
-rw-r--r--src/isodate/tests/test_pickle.py6
-rw-r--r--src/isodate/tzinfo.py14
2 files changed, 20 insertions, 0 deletions
diff --git a/src/isodate/tests/test_pickle.py b/src/isodate/tests/test_pickle.py
index b52f8cb..d24cf4a 100644
--- a/src/isodate/tests/test_pickle.py
+++ b/src/isodate/tests/test_pickle.py
@@ -36,6 +36,12 @@ class TestPickle(unittest.TestCase):
self.assertEqual(len(failed), 0, "pickle protos failed: %s" %
str(failed))
+ def test_pickle_utc(self):
+ '''
+ isodate.UTC objects remain the same after pickling.
+ '''
+ self.assertTrue(isodate.UTC is pickle.loads(pickle.dumps(isodate.UTC)))
+
def test_suite():
'''
diff --git a/src/isodate/tzinfo.py b/src/isodate/tzinfo.py
index b41f058..573b7b8 100644
--- a/src/isodate/tzinfo.py
+++ b/src/isodate/tzinfo.py
@@ -36,10 +36,24 @@ class Utc(tzinfo):
'''
return ZERO
+ def __reduce__(self):
+ '''
+ When unpickling a Utc object, return the default instance below, UTC.
+ '''
+ return _Utc, ()
+
+
UTC = Utc()
# the default instance for UTC.
+def _Utc():
+ '''
+ Helper function for unpickling a Utc object.
+ '''
+ return UTC
+
+
class FixedOffset(tzinfo):
'''
A class building tzinfo objects for fixed-offset time zones.