Skip to content

Commit

Permalink
Fix unpickling of instances those base class changed to a new-style c…
Browse files Browse the repository at this point in the history
…lass. (#208)

If the instance was created before Zope 4.0b2 unpickling broke because in 4.0b2 all classes became new-style classes.

Fixes #205.
  • Loading branch information
Michael Howitz committed Oct 24, 2017
1 parent 442e66a commit 1736580
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -20,6 +20,9 @@ Bugfixes

- Move _html to HTTPBaseResponse since it is shared by HTTPResponse and WSGIResponse.

- Fix unpickling of instances created before 4.0b2 those classes changed from
old-style classes to new-style classes.

Changes
+++++++

Expand Down
9 changes: 8 additions & 1 deletion src/Shared/DC/Scripts/Bindings.py
Expand Up @@ -50,10 +50,17 @@ class NameAssignments(object):

__allow_access_to_unprotected_subobjects__ = 1

def __init__(self, mapping):
def __init__(self, mapping=None):
# mapping is presumably the REQUEST or compatible equivalent.
# Note that we take care not to store expression texts in the ZODB.

# The default value is needed for unpickling instances of this class
# which where created before 4.0b2 where this class was still an old
# style class. For details see
# https://github.com/zopefoundation/Zope/issues/205
asgns = {}
if mapping is None:
mapping = {}
_isLegalName = self._isLegalName
for name, expr in self._exprs:
if name in mapping:
Expand Down
6 changes: 5 additions & 1 deletion src/Shared/DC/Scripts/Signature.py
Expand Up @@ -21,7 +21,11 @@
@total_ordering
class FuncCode(object):

def __init__(self, varnames, argcount):
def __init__(self, varnames=(), argcount=-1):
# The default values are needed for unpickling instances of this class
# which where created before 4.0b2 where this class was still an old
# style class. For details see
# https://github.com/zopefoundation/Zope/issues/205
self.co_varnames = varnames
self.co_argcount = argcount

Expand Down
13 changes: 11 additions & 2 deletions src/ZPublisher/BeforeTraverse.py
Expand Up @@ -86,7 +86,12 @@ class MultiHook(object):
MultiHook calls the named hook from the class of the container, then
the prior hook, then all the hooks in its list.
"""
def __init__(self, hookname, prior, defined_in_class):
def __init__(self, hookname='<undefined hookname>', prior=None,
defined_in_class=False):
# The default values are needed for unpickling instances of this class
# which where created before 4.0b2 where this class was still an old
# style class. For details see
# https://github.com/zopefoundation/Zope/issues/205
self._hookname = hookname
self._prior = prior
self._defined_in_class = defined_in_class
Expand Down Expand Up @@ -120,7 +125,11 @@ class NameCaller(object):
>>> registerBeforeTraverse(folder, NameCaller('preop'), 'XApp')
"""

def __init__(self, name):
def __init__(self, name='<undefined name>'):
# The default value is needed for unpickling instances of this class
# which where created before 4.0b2 where this class was still an old
# style class. For details see
# https://github.com/zopefoundation/Zope/issues/205
self.name = name

def __call__(self, container, request):
Expand Down

0 comments on commit 1736580

Please sign in to comment.