Death to __of__!

parent 22f2299a
...@@ -192,7 +192,7 @@ class Traversable: ...@@ -192,7 +192,7 @@ class Traversable:
if ns: if ns:
try: try:
next = namespaceLookup( next = namespaceLookup(
ns, nm, obj, self.REQUEST).__of__(obj) ns, nm, obj, self.REQUEST)
if restricted and not validate( if restricted and not validate(
obj, obj, name, next): obj, obj, name, next):
raise Unauthorized(name) raise Unauthorized(name)
...@@ -260,7 +260,7 @@ class Traversable: ...@@ -260,7 +260,7 @@ class Traversable:
Interface, name) Interface, name)
if next is not None: if next is not None:
next = next.__of__(obj) next = next
if restricted and not validate(obj, obj, name, next): if restricted and not validate(obj, obj, name, next):
raise Unauthorized(name) raise Unauthorized(name)
elif bobo_traverse is not None: elif bobo_traverse is not None:
......
...@@ -209,9 +209,9 @@ class view(zope_app_view): ...@@ -209,9 +209,9 @@ class view(zope_app_view):
view = component.queryMultiAdapter((self, request), name=name, view = component.queryMultiAdapter((self, request), name=name,
default=None) default=None)
if view is not None: if view is not None:
return view.__of__(self) return view
m = class_.publishTraverse.__get__(self).__of__(self) m = class_.publishTraverse.__get__(self)
return m(request, name) return m(request, name)
else: else:
...@@ -223,7 +223,7 @@ class view(zope_app_view): ...@@ -223,7 +223,7 @@ class view(zope_app_view):
view = component.queryMultiAdapter((self, request), name=name, view = component.queryMultiAdapter((self, request), name=name,
default=None) default=None)
if view is not None: if view is not None:
return view.__of__(self) return view
raise NotFoundError(self, name, request) raise NotFoundError(self, name, request)
......
...@@ -41,11 +41,6 @@ class Z2ProviderExpression(StringExpr): ...@@ -41,11 +41,6 @@ class Z2ProviderExpression(StringExpr):
if provider is None: if provider is None:
raise cp_interfaces.ContentProviderLookupError(name) raise cp_interfaces.ContentProviderLookupError(name)
# Wrap the content provider's in its __parent__, whatever that
# may be (typically the view).
if getattr(provider, '__of__', None) is not None:
provider = provider.__of__(provider.__parent__)
# Insert the data gotten from the context # Insert the data gotten from the context
addTALNamespaceData(provider, econtext) addTALNamespaceData(provider, econtext)
......
...@@ -18,7 +18,6 @@ $Id$ ...@@ -18,7 +18,6 @@ $Id$
import os import os
import urllib import urllib
import Acquisition
from OFS.Traversable import Traversable as OFSTraversable from OFS.Traversable import Traversable as OFSTraversable
from zope.app.publisher.browser.resources import empty from zope.app.publisher.browser.resources import empty
from zope.app.publisher.fileresource import File, Image from zope.app.publisher.fileresource import File, Image
...@@ -28,12 +27,11 @@ from zope.component import getMultiAdapter ...@@ -28,12 +27,11 @@ from zope.component import getMultiAdapter
from zope.component.interfaces import IResource from zope.component.interfaces import IResource
from zope.datetime import time as timeFromDateTimeString from zope.datetime import time as timeFromDateTimeString
from zope.traversing.browser.interfaces import IAbsoluteURL from zope.traversing.browser.interfaces import IAbsoluteURL
from Products.Five.browser import BrowserView from Products.Five.browser import BrowserView
_marker = [] _marker = []
class Resource(Acquisition.Explicit): class Resource(object):
"""A publishable resource """A publishable resource
""" """
implements(IResource) implements(IResource)
...@@ -63,7 +61,7 @@ class PageTemplateResource(BrowserView, Resource): ...@@ -63,7 +61,7 @@ class PageTemplateResource(BrowserView, Resource):
"""Rendered content""" """Rendered content"""
# ZPublisher might have called setBody with an incorrect URL # ZPublisher might have called setBody with an incorrect URL
# we definitely don't want that if we are plain html # we definitely don't want that if we are plain html
self.request.RESPONSE.setBase(None) self.request.response.setBase(None)
pt = self.context pt = self.context
return pt(self.request) return pt(self.request)
...@@ -229,11 +227,7 @@ class DirectoryResource(BrowserView, Resource, OFSTraversable): ...@@ -229,11 +227,7 @@ class DirectoryResource(BrowserView, Resource, OFSTraversable):
resource = factory(name, filename)(self.request) resource = factory(name, filename)(self.request)
resource.__name__ = name resource.__name__ = name
resource.__parent__ = self resource.__parent__ = self
# XXX __of__ wrapping is usually done on traversal. return resource
# However, we don't want to subclass Traversable (or do we?)
# The right thing should probably be a specific (and very simple)
# traverser that does __getitem__ and __of__.
return resource.__of__(self)
class DirectoryResourceFactory(ResourceFactory): class DirectoryResourceFactory(ResourceFactory):
......
...@@ -221,7 +221,6 @@ so we get ('',) instead of ('eagle',): ...@@ -221,7 +221,6 @@ so we get ('',) instead of ('eagle',):
Wrap into an acquisition so that imPermissionRole objects can be Wrap into an acquisition so that imPermissionRole objects can be
evaluated. __roles__ is a imPermissionRole object: evaluated. __roles__ is a imPermissionRole object:
>>> view = view.__of__(self.folder.testoid)
>>> view_roles = getattr(view, '__roles__', None) >>> view_roles = getattr(view, '__roles__', None)
>>> view_roles >>> view_roles
('Manager',) ('Manager',)
......
...@@ -22,23 +22,20 @@ ZopeTwoPageTemplateFile with the proper acquisition context. ...@@ -22,23 +22,20 @@ ZopeTwoPageTemplateFile with the proper acquisition context.
$Id$ $Id$
""" """
import Acquisition
import zope.app.form.browser.objectwidget import zope.app.form.browser.objectwidget
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass as initializeClass from Globals import InitializeClass as initializeClass
from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
class ObjectWidgetView(Acquisition.Explicit, class ObjectWidgetView(zope.app.form.browser.objectwidget.ObjectWidgetView):
zope.app.form.browser.objectwidget.ObjectWidgetView):
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectPublic() security.declareObjectPublic()
template = ZopeTwoPageTemplateFile('objectwidget.pt') template = ViewPageTemplateFile('objectwidget.pt')
initializeClass(ObjectWidgetView) initializeClass(ObjectWidgetView)
class ObjectWidgetClass(Acquisition.Explicit, class ObjectWidgetClass(zope.app.form.browser.objectwidget.ObjectWidget):
zope.app.form.browser.objectwidget.ObjectWidget):
def __init__(self, context, request, factory, **kw): def __init__(self, context, request, factory, **kw):
super(ObjectWidgetClass, self).__init__(context, request, factory, **kw) super(ObjectWidgetClass, self).__init__(context, request, factory, **kw)
...@@ -58,8 +55,4 @@ class ObjectWidgetClass(Acquisition.Explicit, ...@@ -58,8 +55,4 @@ class ObjectWidgetClass(Acquisition.Explicit,
val = self.context.schema[name].default val = self.context.schema[name].default
self.getSubWidget(name).setRenderedValue(val) self.getSubWidget(name).setRenderedValue(val)
def ObjectWidget(context, request, factory, **kw): ObjectWidget = ObjectWidetClass
"""Return an ObjectWidget suitable in the Five environment, with
right acquisition context"""
return ObjectWidgetClass(context, request, factory, **kw
).__of__(context.context)
...@@ -41,9 +41,6 @@ class ViewletManagerBase(origManagerBase, Acquisition.Explicit): ...@@ -41,9 +41,6 @@ class ViewletManagerBase(origManagerBase, Acquisition.Explicit):
raise zope.component.interfaces.ComponentLookupError( raise zope.component.interfaces.ComponentLookupError(
'No provider with name `%s` found.' %name) 'No provider with name `%s` found.' %name)
# Wrap the viewlet for security lookups
viewlet = viewlet.__of__(viewlet.context)
# If the viewlet cannot be accessed, then raise an # If the viewlet cannot be accessed, then raise an
# unauthorized error # unauthorized error
if not guarded_hasattr(viewlet, 'render'): if not guarded_hasattr(viewlet, 'render'):
...@@ -65,8 +62,6 @@ class ViewletManagerBase(origManagerBase, Acquisition.Explicit): ...@@ -65,8 +62,6 @@ class ViewletManagerBase(origManagerBase, Acquisition.Explicit):
# the object has a real context from which to determine owner # the object has a real context from which to determine owner
# security. # security.
for name, viewlet in viewlets: for name, viewlet in viewlets:
if getattr(viewlet, '__of__', None) is not None:
viewlet = viewlet.__of__(viewlet.__parent__)
if guarded_hasattr(viewlet, 'render'): if guarded_hasattr(viewlet, 'render'):
results.append((name, viewlet)) results.append((name, viewlet))
return results return results
......
...@@ -95,7 +95,7 @@ class DefaultPublishTraverse(object): ...@@ -95,7 +95,7 @@ class DefaultPublishTraverse(object):
request.response.setStatus(200) request.response.setStatus(200)
# We don't need to do the docstring security check # We don't need to do the docstring security check
# for views, so lets skip it and return the object here. # for views, so lets skip it and return the object here.
return subobject.__of__(object) return subobject
# No view found. Reraise the error raised by __bobo_traverse__ # No view found. Reraise the error raised by __bobo_traverse__
raise e raise e
else: else:
...@@ -105,9 +105,10 @@ class DefaultPublishTraverse(object): ...@@ -105,9 +105,10 @@ class DefaultPublishTraverse(object):
subobject = getattr(object, name) subobject = getattr(object, name)
else: else:
# We try to fall back to a view: # We try to fall back to a view:
subobject = queryMultiAdapter((object, request), Interface, name) subobject = queryMultiAdapter((object, request), Interface,
name)
if subobject is not None: if subobject is not None:
return subobject.__of__(object) return subobject
# And lastly, of there is no view, try acquired attributes, but # And lastly, of there is no view, try acquired attributes, but
# only if there is no __bobo_traverse__: # only if there is no __bobo_traverse__:
...@@ -311,8 +312,7 @@ class BaseRequest: ...@@ -311,8 +312,7 @@ class BaseRequest:
ob2 = namespaceLookup(ns, nm, ob, self) ob2 = namespaceLookup(ns, nm, ob, self)
except TraversalError: except TraversalError:
raise KeyError(ob, name) raise KeyError(ob, name)
return ob2
return ob2.__of__(ob)
if name == '.': if name == '.':
return ob return ob
......
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