Commit d6cf38e6 authored by Jérome Perrin's avatar Jérome Perrin

patches: fix DateTime 2.12.7 copy_reg monkey patch so that it does not affect...

patches: fix DateTime 2.12.7 copy_reg monkey patch so that it does not affect pickle 🤔 is this really safe ? 🚧
parent 67b0d1f7
...@@ -248,6 +248,34 @@ def DateTime_parse(self, st, datefmt=getDefaultDateFormat()): ...@@ -248,6 +248,34 @@ 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.
# DateTime 3 has 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. This was fe81af1 (Add `_dt_reconstructor` function introduced in
# DateTime 2.12.7., 2012-09-17)
import six
if six.PY2:
import 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