Commit 04c41f87 authored by Jérome Perrin's avatar Jérome Perrin

patches: make Shared.DC.Scripts.Bindings and ZPublisher.BeforeTraverse.MultiHook new-style classes

This backports parts of zope 4 commits [bb7837c66 (Explicitly make all
classes new-style., 2017-09-15)](https://github.com/zopefoundation/Zope/commit/bb7837c66) and [173658008 (Fix unpickling of instances
those base class changed to a new-style class. (#208), 2017-10-24)](https://github.com/zopefoundation/Zope/commit/173658008) for zope2.

This is done for two reasons:
 - so that business template XML are same when exported from zope4
   and from zope2
 - so that a business template created from zope4 can still be
   installed on zope2.

See merge request !1596
parents 402c1acb 75d812ea
...@@ -107,6 +107,8 @@ from Products.ERP5Type.patches import WSGITask ...@@ -107,6 +107,8 @@ from Products.ERP5Type.patches import WSGITask
if six.PY2: if six.PY2:
# XXX-zope4py3: urllib2 removed (see future/backports/urllib/request.py) # XXX-zope4py3: urllib2 removed (see future/backports/urllib/request.py)
from Products.ERP5Type.patches import urllib_opener from Products.ERP5Type.patches import urllib_opener
from Products.ERP5Type.patches import SharedDCScriptsBindings
from Products.ERP5Type.patches import ZPublisherBeforeTraverse
# These symbols are required for backward compatibility # These symbols are required for backward compatibility
from Products.ERP5Type.patches.PropertyManager import ERP5PropertyManager from Products.ERP5Type.patches.PropertyManager import ERP5PropertyManager
......
...@@ -278,7 +278,6 @@ def DateTime_parse(self, st, datefmt=getDefaultDateFormat()): ...@@ -278,7 +278,6 @@ def DateTime_parse(self, st, datefmt=getDefaultDateFormat()):
DateTimeKlass._parse = DateTime_parse DateTimeKlass._parse = DateTime_parse
# DateTime 3 removed exceptions as class attributes (since # DateTime 3 removed exceptions as class attributes (since
# zopefoundation/DateTime commit 8114618 ), but we have some code expecting # zopefoundation/DateTime commit 8114618 ), but we have some code expecting
# these attributes, so undo this patch for convenience. # these attributes, so undo this patch for convenience.
...@@ -286,3 +285,13 @@ DateTimeKlass.DateTimeError = DateTimeError ...@@ -286,3 +285,13 @@ DateTimeKlass.DateTimeError = DateTimeError
DateTimeKlass.SyntaxError = SyntaxError DateTimeKlass.SyntaxError = SyntaxError
DateTimeKlass.DateError = DateError DateTimeKlass.DateError = DateError
DateTimeKlass.TimeError = TimeError DateTimeKlass.TimeError = TimeError
# BBB undo patch from DateTime 2.12 , which patches
# copy_reg._reconstructor with a function that appears as
# `DateTime.DateTime._dt_reconstructor` in pickles.
# See https://github.com/zopefoundation/DateTime/blob/2.12.8/src/DateTime/DateTime.py#L1863-L1874
# This patch is no longer needed once we are using DateTime >= 3 so
# it is not needed on python3 (copy_reg does not exist on python3)
import copy_reg
copy_reg._reconstructor.__module__ = 'copy_reg'
copy_reg._reconstructor.__name__ = '_reconstructor'
import Shared.DC.Scripts.Bindings
# Make Shared.DC.Scripts.Bindings a new style classes already on Zope2, so that
# we can install business templates exported on Zope4 in Zope2 instances.
_NameAssignments = Shared.DC.Scripts.Bindings.NameAssignments
if not isinstance(_NameAssignments, type):
class NameAssignments(_NameAssignments, object):
def __init__(self, mapping=None):
if mapping is None:
mapping = {}
_NameAssignments.__init__(self, mapping)
NameAssignments.__module__ = _NameAssignments.__module__
Shared.DC.Scripts.Bindings.NameAssignments = NameAssignments
import ZPublisher.BeforeTraverse
# Make ZPublisher.BeforeTraverse.MultiHook a new style classes already on
# Zope2, so that we can install business templates exported on Zope4 in
# Zope2 instances.
_MultiHook = ZPublisher.BeforeTraverse.MultiHook
if not isinstance(_MultiHook, type):
class MultiHook(_MultiHook, object):
def __init__(self, hookname='<undefined hookname>', prior=None,
defined_in_class=False):
_MultiHook.__init__(self, hookname, prior, defined_in_class)
def __repr__(self):
# BBB keep the old class repr for testBeforeTraverse
return '<ZPublisher.BeforeTraverse.MultiHook instance at 0x%0x (patched in %r)>' % (
id(self), __file__)
MultiHook.__module__ = _MultiHook.__module__
ZPublisher.BeforeTraverse.MultiHook = MultiHook
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