Skip to content

Commit

Permalink
Merge pull request #14 from plone/davisagli-replaceable
Browse files Browse the repository at this point in the history
adjust ReplaceableWrapper to work in Zope 4
  • Loading branch information
pbauer authored Nov 16, 2017
2 parents 1c6084c + c1b3a95 commit cc98886
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ New features:

Bug fixes:

- *add item here*
- Fix webdav PUT of index_html to work in Zope 4.
[davisagli]


1.2.3 (2017-03-27)
Expand Down
19 changes: 14 additions & 5 deletions src/plone/app/folder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from webdav.NullResource import NullResource
from zope.interface import implementer
from App.class_init import InitializeClass
import Acquisition

# to keep backward compatibility
has_btree = 1


class ReplaceableWrapper:
class ReplaceableWrapper(Acquisition.Implicit):
""" a wrapper around an object to make it replaceable """

def __init__(self, ob):
Expand All @@ -26,7 +27,12 @@ def __init__(self, ob):
def __getattr__(self, name):
if name == '__replaceable__':
return REPLACEABLE
return getattr(self.__ob, name)
ob = object.__getattribute__(self, '_ReplaceableWrapper__ob')
return getattr(ob, name)

def __repr__(self):
return repr(
object.__getattribute__(self, '_ReplaceableWrapper__ob').aq_base)


@implementer(IOrderedContainer)
Expand Down Expand Up @@ -67,15 +73,18 @@ def index_html(self, REQUEST=None, RESPONSE=None):
method = request['REQUEST_METHOD']
if method == 'PUT':
# Very likely a WebDAV client trying to create something
return ReplaceableWrapper(NullResource(self, 'index_html'))
nr = NullResource(self, 'index_html')
nr.__replaceable__ = REPLACEABLE
return nr
elif method in ('GET', 'HEAD', 'POST'):
# Do nothing, let it go and acquire.
pass
else:
raise AttributeError('index_html')
# Acquire from parent
target = aq_parent(aq_inner(self)).aq_acquire('index_html')
return ReplaceableWrapper(aq_base(target).__of__(self))
parent = aq_parent(aq_inner(self))
target = parent.aq_acquire('index_html')
return ReplaceableWrapper(target).__of__(parent).__of__(self)

index_html = ComputedAttribute(index_html, 1)

Expand Down

0 comments on commit cc98886

Please sign in to comment.