mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-11 03:26:37 +03:00
Merge branch 'fix-135' into maint_2_4
This commit is contained in:
commit
0837fc958e
1
NEWS
1
NEWS
|
@ -15,6 +15,7 @@ What's new in psycopg 2.4.6
|
||||||
- connect() raises an exception instead of swallowing keyword arguments
|
- connect() raises an exception instead of swallowing keyword arguments
|
||||||
when a connection string is specified as well (ticket #131).
|
when a connection string is specified as well (ticket #131).
|
||||||
- Discard any result produced by 'executemany()' (ticket #133).
|
- Discard any result produced by 'executemany()' (ticket #133).
|
||||||
|
- Fixed pickling of FixedOffsetTimezone objects (ticket #135).
|
||||||
|
|
||||||
|
|
||||||
What's new in psycopg 2.4.5
|
What's new in psycopg 2.4.5
|
||||||
|
|
|
@ -63,8 +63,7 @@ class FixedOffsetTimezone(datetime.tzinfo):
|
||||||
try:
|
try:
|
||||||
return cls._cache[key]
|
return cls._cache[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
tz = datetime.tzinfo.__new__(cls, offset, name)
|
tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name)
|
||||||
tz.__init__(offset, name)
|
|
||||||
cls._cache[key] = tz
|
cls._cache[key] = tz
|
||||||
return tz
|
return tz
|
||||||
|
|
||||||
|
@ -73,6 +72,10 @@ class FixedOffsetTimezone(datetime.tzinfo):
|
||||||
return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \
|
return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \
|
||||||
% (offset_mins, self._name)
|
% (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):
|
def utcoffset(self, dt):
|
||||||
return self._offset
|
return self._offset
|
||||||
|
|
||||||
|
@ -104,7 +107,6 @@ class LocalTimezone(datetime.tzinfo):
|
||||||
|
|
||||||
This is the exact implementation from the Python 2.3 documentation.
|
This is the exact implementation from the Python 2.3 documentation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def utcoffset(self, dt):
|
def utcoffset(self, dt):
|
||||||
if self._isdst(dt):
|
if self._isdst(dt):
|
||||||
return DSTOFFSET
|
return DSTOFFSET
|
||||||
|
|
|
@ -539,6 +539,24 @@ class FixedOffsetTimezoneTests(unittest.TestCase):
|
||||||
self.assert_(FixedOffsetTimezone(9 * 60) is not FixedOffsetTimezone(9 * 60, 'FOO'))
|
self.assert_(FixedOffsetTimezone(9 * 60) is not FixedOffsetTimezone(9 * 60, 'FOO'))
|
||||||
self.assert_(FixedOffsetTimezone(name='FOO') 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():
|
def test_suite():
|
||||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user