Commit 9bc2e7f0 authored by 's avatar

- synced code with zope.browserpage (this should just simplify the diff...

- synced code with zope.browserpage (this should just simplify the diff without changing any behavior)
- related cleanup
parent 5f5f19ee
...@@ -20,16 +20,16 @@ namespace in ZCML known from zope.app. ...@@ -20,16 +20,16 @@ namespace in ZCML known from zope.app.
import os import os
from inspect import ismethod from inspect import ismethod
from zope import component from zope.component import queryMultiAdapter
from zope.interface import implements
from zope.interface import Interface
from zope.component.zcml import handler
from zope.component.interface import provideInterface from zope.component.interface import provideInterface
from zope.component.zcml import handler
from zope.configuration.exceptions import ConfigurationError from zope.configuration.exceptions import ConfigurationError
from zope.interface import implements
from zope.interface import Interface
from zope.publisher.interfaces import NotFound from zope.publisher.interfaces import NotFound
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.publisher.interfaces.browser import IBrowserPublisher from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.browser import IBrowserRequest from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.security.zcml import Permission from zope.security.zcml import Permission
import zope.browserpage.metaconfigure import zope.browserpage.metaconfigure
...@@ -56,18 +56,12 @@ from Products.Five.metaclass import makeClass ...@@ -56,18 +56,12 @@ from Products.Five.metaclass import makeClass
def page(_context, name, permission, for_, def page(_context, name, permission, for_,
layer=IDefaultBrowserLayer, template=None, class_=None, layer=IDefaultBrowserLayer, template=None, class_=None,
allowed_interface=None, allowed_attributes=None, allowed_interface=None, allowed_attributes=None,
attribute='__call__', menu=None, title=None, attribute='__call__', menu=None, title=None,
): ):
_handle_menu(_context, menu, title, [for_], name, permission) _handle_menu(_context, menu, title, [for_], name, permission)
if not (class_ or template): if not (class_ or template):
raise ConfigurationError("Must specify a class or template") raise ConfigurationError("Must specify a class or template")
if allowed_attributes is None:
allowed_attributes = []
if allowed_interface is not None:
for interface in allowed_interface:
allowed_attributes.extend(interface.names(all=True))
if attribute != '__call__': if attribute != '__call__':
if template: if template:
...@@ -92,6 +86,7 @@ def page(_context, name, permission, for_, ...@@ -92,6 +86,7 @@ def page(_context, name, permission, for_,
cdict = getSecurityInfo(class_) cdict = getSecurityInfo(class_)
cdict['__name__'] = name cdict['__name__'] = name
if template: if template:
# class and template
new_class = makeClassForTemplate(template, bases=(class_, ), new_class = makeClassForTemplate(template, bases=(class_, ),
cdict=cdict, name=name) cdict=cdict, name=name)
elif attribute != "__call__": elif attribute != "__call__":
...@@ -120,13 +115,19 @@ def page(_context, name, permission, for_, ...@@ -120,13 +115,19 @@ def page(_context, name, permission, for_,
# some security declarations on it so we really shouldn't # some security declarations on it so we really shouldn't
# modify the original. So, instead we make a new class # modify the original. So, instead we make a new class
# with just one base class -- the original # with just one base class -- the original
new_class = makeClass(class_.__name__, new_class = makeClass(class_.__name__,
(class_, BrowserView), cdict) (class_, BrowserView), cdict)
else: else:
# template # template
new_class = makeClassForTemplate(template, name=name) new_class = makeClassForTemplate(template, name=name)
if allowed_attributes is None:
allowed_attributes = []
if allowed_interface is not None:
for interface in allowed_interface:
allowed_attributes.extend(interface.names(all=True))
_handle_for(_context, for_) _handle_for(_context, for_)
_context.action( _context.action(
...@@ -135,6 +136,9 @@ def page(_context, name, permission, for_, ...@@ -135,6 +136,9 @@ def page(_context, name, permission, for_,
args = ('registerAdapter', args = ('registerAdapter',
new_class, (for_, layer), Interface, name, _context.info), new_class, (for_, layer), Interface, name, _context.info),
) )
# Security
_context.action( _context.action(
discriminator = ('five:protectClass', new_class), discriminator = ('five:protectClass', new_class),
callable = protectClass, callable = protectClass,
...@@ -166,6 +170,7 @@ def page(_context, name, permission, for_, ...@@ -166,6 +170,7 @@ def page(_context, name, permission, for_,
args = (new_class,) args = (new_class,)
) )
class pages(zope.browserpage.metaconfigure.pages): class pages(zope.browserpage.metaconfigure.pages):
def page(self, _context, name, attribute='__call__', template=None, def page(self, _context, name, attribute='__call__', template=None,
...@@ -200,6 +205,7 @@ class view(zope.browserpage.metaconfigure.view): ...@@ -200,6 +205,7 @@ class view(zope.browserpage.metaconfigure.view):
pages = {} pages = {}
for pname, attribute, template in self.pages: for pname, attribute, template in self.pages:
if template: if template:
cdict[pname] = ViewPageTemplateFile(template) cdict[pname] = ViewPageTemplateFile(template)
if attribute and attribute != name: if attribute and attribute != name:
...@@ -222,8 +228,7 @@ class view(zope.browserpage.metaconfigure.view): ...@@ -222,8 +228,7 @@ class view(zope.browserpage.metaconfigure.view):
if name in pages: if name in pages:
return getattr(self, pages[name]) return getattr(self, pages[name])
view = component.queryMultiAdapter((self, request), name=name, view = queryMultiAdapter((self, request), name=name)
default=None)
if view is not None: if view is not None:
return view return view
...@@ -236,8 +241,7 @@ class view(zope.browserpage.metaconfigure.view): ...@@ -236,8 +241,7 @@ class view(zope.browserpage.metaconfigure.view):
if name in pages: if name in pages:
return getattr(self, pages[name]) return getattr(self, pages[name])
view = component.queryMultiAdapter((self, request), name=name, view = queryMultiAdapter((self, request), name=name)
default=None)
if view is not None: if view is not None:
return view return view
...@@ -266,10 +270,10 @@ class view(zope.browserpage.metaconfigure.view): ...@@ -266,10 +270,10 @@ class view(zope.browserpage.metaconfigure.view):
cname = str(name) cname = str(name)
except: except:
cname = "GeneratedClass" cname = "GeneratedClass"
cdict['__name__'] = name cdict['__name__'] = name
newclass = makeClass(cname, bases, cdict) newclass = makeClass(cname, bases, cdict)
_handle_for(_context, for_) _handle_for(_context, for_)
if self.provides is not None: if self.provides is not None:
...@@ -287,15 +291,15 @@ class view(zope.browserpage.metaconfigure.view): ...@@ -287,15 +291,15 @@ class view(zope.browserpage.metaconfigure.view):
newclass, (for_, layer), self.provides, name, newclass, (for_, layer), self.provides, name,
_context.info), _context.info),
) )
# Security # Security
_context.action( _context.action(
discriminator = ('five:protectClass', newclass), discriminator = ('five:protectClass', newclass),
callable = protectClass, callable = protectClass,
args = (newclass, permission) args = (newclass, permission)
) )
if allowed_attributes: if allowed_attributes:
for attr in allowed_attributes: for attr in allowed_attributes:
_context.action( _context.action(
...@@ -303,7 +307,7 @@ class view(zope.browserpage.metaconfigure.view): ...@@ -303,7 +307,7 @@ class view(zope.browserpage.metaconfigure.view):
callable = protectName, callable = protectName,
args = (newclass, attr, permission) args = (newclass, attr, permission)
) )
# Make everything else private # Make everything else private
allowed = allowed_attributes or [] allowed = allowed_attributes or []
private_attrs = [name for name in dir(newclass) private_attrs = [name for name in dir(newclass)
...@@ -316,7 +320,7 @@ class view(zope.browserpage.metaconfigure.view): ...@@ -316,7 +320,7 @@ class view(zope.browserpage.metaconfigure.view):
callable = protectName, callable = protectName,
args = (newclass, attr, CheckerPrivateId, False) args = (newclass, attr, CheckerPrivateId, False)
) )
# Protect the class # Protect the class
_context.action( _context.action(
discriminator = ('five:initialize:class', newclass), discriminator = ('five:initialize:class', newclass),
...@@ -441,6 +445,7 @@ def resourceDirectory(_context, name, directory, layer=IDefaultBrowserLayer, ...@@ -441,6 +445,7 @@ def resourceDirectory(_context, name, directory, layer=IDefaultBrowserLayer,
args = (new_class,) args = (new_class,)
) )
class ViewMixinForAttributes(BrowserView, class ViewMixinForAttributes(BrowserView,
zope.browserpage.metaconfigure.simple): zope.browserpage.metaconfigure.simple):
...@@ -454,6 +459,7 @@ class ViewMixinForAttributes(BrowserView, ...@@ -454,6 +459,7 @@ class ViewMixinForAttributes(BrowserView,
def __call__(self): def __call__(self):
return getattr(self, self.__page_attribute__) return getattr(self, self.__page_attribute__)
class ViewMixinForTemplates(BrowserView): class ViewMixinForTemplates(BrowserView):
# Cloned from zope.app.pagetemplate.simpleviewclass.simple # Cloned from zope.app.pagetemplate.simpleviewclass.simple
implements(IBrowserPublisher) implements(IBrowserPublisher)
...@@ -489,4 +495,3 @@ def makeClassForTemplate(filename, globals=None, used_for=None, ...@@ -489,4 +495,3 @@ def makeClassForTemplate(filename, globals=None, used_for=None,
class_.__used_for__ = used_for class_.__used_for__ = used_for
return class_ return class_
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