Commit 47961b8f authored by Jérome Perrin's avatar Jérome Perrin

patches: patch DateTime 2.12.7 to prevent DateTime.DateTime._dt_reconstructor in pickle

Having DateTime.DateTime._dt_reconstructor in pickles is not really
a problem, because DateTime keep compatibility for this, but it makes
Business Template output different between DateTime 2 and DateTime 3.
parent 3e774c47
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
from DateTime import DateTime as DateTimeKlass from DateTime import DateTime as DateTimeKlass
import math import math
import six
from DateTime.DateTime import _calcSD, _calcDependentSecond, _calcYMDHMS,\ from DateTime.DateTime import _calcSD, _calcDependentSecond, _calcYMDHMS,\
getDefaultDateFormat, _correctYear, _calcHMS, _calcDependentSecond2, DateTimeError,\ getDefaultDateFormat, _correctYear, _calcHMS, _calcDependentSecond2, DateTimeError,\
SyntaxError, DateError, TimeError, localtime, time SyntaxError, DateError, TimeError, localtime, time
...@@ -248,6 +249,45 @@ def DateTime_parse(self, st, datefmt=getDefaultDateFormat()): ...@@ -248,6 +249,45 @@ def DateTime_parse(self, st, datefmt=getDefaultDateFormat()):
DateTimeKlass._parse = DateTime_parse DateTimeKlass._parse = DateTime_parse
# DateTime 2.12.7 and 2.12.8 shipped with a monkey patch to copy_reg module,
# introduced in zopefoundation/DateTime commit 1bb6e68 (Added forward
# compatibility with DateTime 3 pickle format., 2012-08-10).
# This patch was problematic, because copy_reg._reconstructor is included in
# pickle protocol 1, (which is the protocol used by business template):
#
# >>> import pickle
# >>> class C(object):
# ... pass
# ...
# >>> pickle.dumps(C(), 1)
# 'ccopy_reg\n_reconstructor\nq\x00(c__main__\nC\nq\x01c__builtin__\nobject\nq\x02Ntq\x03Rq\x04.'
#
# because copyreg._reconstructor was monkey patched to be
# DateTime.DateTime._dt_reconstructor, the pickles included reference to
# DateTime.DateTime._dt_reconstructor.
# After DateTime monkey patch was loaded, the pickle was like this:
#
# >>> pickle.dumps(C(), 1)
# 'cDateTime.DateTime\n_dt_reconstructor\nq\x00(c__main__\nC\nq\x01c__builtin__\nobject\nq\x02Ntq\x03Rq\x04.'
#
# To prevent this to appear in pickle, we monkey patch the monkey patched
# functions, to restore the original copy_reg._reconstructor name.
#
# Note that DateTime 3 provides support for this, it has DateTime.DateTime._dt_reconstructor
# symbol, but that is no longer monkey patched in copy_reg, it is only here
# for compatibility, because the symbol appears in pickle. For reference,
# this was fe81af1 (Add `_dt_reconstructor` function introduced in DateTime
# 2.12.7., 2012-09-17)
if six.PY2:
# only apply the patch on python 2, because on python3 we have DateTime > 3
# and because copy_reg was renamed on python3
import copy_reg
if copy_reg._reconstructor.__module__ != 'copy_reg':
copy_reg._reconstructor.__module__ = 'copy_reg'
copy_reg._reconstructor.__name__ = '_reconstructor'
if __name__ == '__main__': if __name__ == '__main__':
for i in ('2007/01/02 12:34:56.789', for i in ('2007/01/02 12:34:56.789',
'2007/01/02 12:34:56.789 GMT+0200', '2007/01/02 12:34:56.789 GMT+0200',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment