mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
Fixed pickling of FixedOffsetTimezone objects
I have also verified that the fixed class can unpickle instance pickled with the buggy one and viceversa. Fixes ticket #135.
This commit is contained in:
parent
a33c0670fd
commit
1feb179fba
1
NEWS
1
NEWS
|
@ -24,6 +24,7 @@ What's new in psycopg 2.4.6
|
|||
- connect() raises an exception instead of swallowing keyword arguments
|
||||
when a connection string is specified as well (ticket #131).
|
||||
- Discard any result produced by 'executemany()' (ticket #133).
|
||||
- Fixed pickling of FixedOffsetTimezone objects (ticket #135).
|
||||
- 'errorcodes' map updated to PostgreSQL 9.2.
|
||||
|
||||
|
||||
|
|
|
@ -72,6 +72,10 @@ class FixedOffsetTimezone(datetime.tzinfo):
|
|||
return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \
|
||||
% (offset_mins, self._name)
|
||||
|
||||
def __getinitargs__(self):
|
||||
offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60
|
||||
return (offset_mins, self._name)
|
||||
|
||||
def utcoffset(self, dt):
|
||||
return self._offset
|
||||
|
||||
|
@ -86,7 +90,7 @@ class FixedOffsetTimezone(datetime.tzinfo):
|
|||
return "%+03d:%d" % (hours, minutes)
|
||||
else:
|
||||
return "%+03d" % hours
|
||||
|
||||
|
||||
def dst(self, dt):
|
||||
return ZERO
|
||||
|
||||
|
@ -103,7 +107,6 @@ class LocalTimezone(datetime.tzinfo):
|
|||
|
||||
This is the exact implementation from the Python 2.3 documentation.
|
||||
"""
|
||||
|
||||
def utcoffset(self, dt):
|
||||
if self._isdst(dt):
|
||||
return DSTOFFSET
|
||||
|
|
|
@ -539,6 +539,24 @@ class FixedOffsetTimezoneTests(unittest.TestCase):
|
|||
self.assert_(FixedOffsetTimezone(9 * 60) is not FixedOffsetTimezone(9 * 60, 'FOO'))
|
||||
self.assert_(FixedOffsetTimezone(name='FOO') is not FixedOffsetTimezone(9 * 60, 'FOO'))
|
||||
|
||||
def test_pickle(self):
|
||||
# ticket #135
|
||||
import pickle
|
||||
|
||||
tz11 = FixedOffsetTimezone(60)
|
||||
tz12 = FixedOffsetTimezone(120)
|
||||
for proto in [-1, 0, 1, 2]:
|
||||
tz21, tz22 = pickle.loads(pickle.dumps([tz11, tz12], proto))
|
||||
self.assertEqual(tz11, tz21)
|
||||
self.assertEqual(tz12, tz22)
|
||||
|
||||
tz11 = FixedOffsetTimezone(60, name='foo')
|
||||
tz12 = FixedOffsetTimezone(120, name='bar')
|
||||
for proto in [-1, 0, 1, 2]:
|
||||
tz21, tz22 = pickle.loads(pickle.dumps([tz11, tz12], proto))
|
||||
self.assertEqual(tz11, tz21)
|
||||
self.assertEqual(tz12, tz22)
|
||||
|
||||
def test_suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user