Ensures UTC stays a singleton
This commit is contained in:
parent
8c68bde1f8
commit
aadd9e4eb4
@ -38,6 +38,9 @@ class FixedOffset(tzinfo):
|
||||
def __getinitargs__(self):
|
||||
return self.__offset, self.__name
|
||||
|
||||
def __reduce__(self):
|
||||
return _UTC, ()
|
||||
|
||||
def utcoffset(self, dt):
|
||||
return self.__offset
|
||||
|
||||
@ -50,3 +53,12 @@ class FixedOffset(tzinfo):
|
||||
|
||||
utc = FixedOffset(0, "UTC")
|
||||
"""Fixed offset timezone representing UTC."""
|
||||
|
||||
|
||||
def _UTC():
|
||||
"""Factory function for utc unpickling.
|
||||
|
||||
Makes sure that unpickling a utc instance always returns the same
|
||||
module global.
|
||||
"""
|
||||
return utc
|
||||
|
||||
@ -48,9 +48,11 @@ class TestTimestamp(unittest.TestCase):
|
||||
|
||||
dc = copy.deepcopy(d)
|
||||
self.assertEqual(dc, t.as_datetime())
|
||||
self.assertEqual(d.tzinfo, dc.tzinfo)
|
||||
|
||||
dp = pickle.loads(pickle.dumps(d))
|
||||
self.assertEqual(dp, t.as_datetime())
|
||||
self.assertEqual(d.tzinfo, dp.tzinfo)
|
||||
|
||||
def test_exceptions(self):
|
||||
self.assertRaises(TypeError, Timestamp)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user