summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarno Saarimäki <jarno.saarimaki@eniram.fi>2015-11-27 13:58:50 (GMT)
committerJarno Saarimäki <jarno.saarimaki@eniram.fi>2015-11-27 14:09:10 (GMT)
commit79b8d42cc2629b53a7a696171221d7bd3a79b30c (patch)
treeb1666540729b9f628e1c75576cfeb5bf5e0ff8d8
parent27d3bca47e4d39bd5038665726fb157577c5abfa (diff)
downloadisodate-79b8d42cc2629b53a7a696171221d7bd3a79b30c.tar.gz
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.