[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/publisher/ The
presentation service is gone.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Sep 17 12:15:54 EDT 2004
Log message for revision 27578:
The presentation service is gone.
Use adapter service instead. Make layers and skins interfaces. Layers and
skins are also utilities, so that they can be easily looked up.
Changed:
U Zope3/trunk/src/zope/app/publisher/browser/i18nresourcemeta.py
U Zope3/trunk/src/zope/app/publisher/browser/icon.py
U Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py
U Zope3/trunk/src/zope/app/publisher/browser/resourcemeta.py
U Zope3/trunk/src/zope/app/publisher/browser/resources.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_icondirective.py
U Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py
U Zope3/trunk/src/zope/app/publisher/xmlrpc/metaconfigure.py
-=-
Modified: Zope3/trunk/src/zope/app/publisher/browser/i18nresourcemeta.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/i18nresourcemeta.py 2004-09-17 16:15:52 UTC (rev 27577)
+++ Zope3/trunk/src/zope/app/publisher/browser/i18nresourcemeta.py 2004-09-17 16:15:54 UTC (rev 27578)
@@ -15,18 +15,18 @@
$Id$
"""
-
+from zope.configuration.exceptions import ConfigurationError
+from zope.interface import Interface
+from zope.publisher.interfaces.browser import IBrowserRequest
from zope.security.proxy import Proxy
from zope.security.checker import CheckerPublic, Checker
-from zope.configuration.exceptions import ConfigurationError
-from zope.app.servicenames import Presentation
+from zope.app import zapi
from zope.app.component.metaconfigure import handler
+from zope.app.publisher.fileresource import File, Image
-from zope.app.publisher.fileresource import File, Image
from i18nfileresource import I18nFileResourceFactory
-from zope.publisher.interfaces.browser import IBrowserRequest
class I18nResource(object):
@@ -34,7 +34,7 @@
default_allowed_attributes = '__call__'
def __init__(self, _context, name=None, defaultLanguage='en',
- layer='default', permission=None):
+ layer=None, permission=None):
self._context = _context
self.name = name
self.defaultLanguage = defaultLanguage
@@ -103,8 +103,9 @@
self._context.action(
discriminator = ('i18n-resource', self.name, self.type, self.layer),
callable = handler,
- args = (Presentation, 'provideResource', self.name, self.type,
- factory, self.layer)
+ args = (zapi.servicenames.Adapters, 'register',
+ (self.layer or self.type,), Interface, self.name, factory,
+ self._context.info)
)
Modified: Zope3/trunk/src/zope/app/publisher/browser/icon.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/icon.py 2004-09-17 16:15:52 UTC (rev 27577)
+++ Zope3/trunk/src/zope/app/publisher/browser/icon.py 2004-09-17 16:15:54 UTC (rev 27578)
@@ -18,13 +18,15 @@
import os
import re
+from zope.interface import Interface
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.configuration.exceptions import ConfigurationError
+
from zope.app import zapi
+from zope.app.component.interface import provideInterface
from zope.app.component.metaconfigure import handler
from zope.app.publisher.browser import metaconfigure
from zope.app.traversing.namespace import getResource
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.configuration.exceptions import ConfigurationError
-from zope.app.component.interface import provideInterface
IName = re.compile('I[A-Z][a-z]')
@@ -60,7 +62,7 @@
return IconView(context, request, self.rname, self.alt)
def IconDirective(_context, name, for_, file=None, resource=None,
- layer='default', alt=None):
+ layer=IBrowserRequest, alt=None):
iname = for_.getName()
@@ -93,9 +95,8 @@
_context.action(
discriminator = ('view', name, vfactory, layer),
callable = handler,
- args = (zapi.servicenames.Presentation, 'provideView',
- for_, name, IBrowserRequest,
- vfactory, layer)
+ args = (zapi.servicenames.Adapters, 'register',
+ (for_, layer), Interface, name, vfactory, _context.info)
)
_context.action(
Modified: Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py 2004-09-17 16:15:52 UTC (rev 27577)
+++ Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py 2004-09-17 16:15:54 UTC (rev 27578)
@@ -15,45 +15,100 @@
$Id$
"""
+from zope.component.interfaces import IDefaultViewName
+from zope.interface.interface import InterfaceClass
+from zope.publisher.interfaces.browser import ILayer, ISkin, IDefaultSkin
+from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app import zapi
-from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app.component.metaconfigure import handler
from zope.app.container.interfaces import IAdding
from zope.app.publisher.browser.globalbrowsermenuservice \
import menuItemDirective
from zope.app.component.contentdirective import ContentDirective
-from zope.app.servicenames import Presentation
# referred to through ZCML
-from zope.app.publisher.browser.resourcemeta import resource, \
- resourceDirectory
+from zope.app.publisher.browser.resourcemeta import resource
+from zope.app.publisher.browser.resourcemeta import resourceDirectory
from zope.app.publisher.browser.i18nresourcemeta import I18nResource
from zope.app.publisher.browser.viewmeta import view
from zope.app.component.interface import provideInterface
-def layer(_context, name):
+from zope.app.component.interface import provideInterface
+
+# Create special modules that contain all layers and skins
+from types import ModuleType as module
+import sys
+layers = module('layers')
+sys.modules['zope.app.layers'] = layers
+
+skins = module('skins')
+sys.modules['zope.app.skins'] = skins
+
+
+def layer(_context, name, base=IBrowserRequest):
+ if ',' in name:
+ raise TypeError("Commas are not allowed in layer names.")
+
+ layer = InterfaceClass(name, (base, ),
+ __doc__='Layer: %s' %name,
+ __module__='zope.app.layers')
+
+ # Add the layer to the skins module.
+ # Note: We have to do this immediately, so that directives using the
+ # InterfaceField can find the layer.
+ setattr(layers, name, layer)
+
+ # Register the layer interface as an interface
_context.action(
+ discriminator = ('interface', 'zope.app.layers.'+name),
+ callable = provideInterface,
+ args = ('zope.app.layers.'+name, layer),
+ kw = {'info': _context.info}
+ )
+
+ # Register the layer interface as a layer
+ _context.action(
discriminator = ('layer', name),
- callable = handler,
- args = (Presentation, 'defineLayer', name, _context.info)
+ callable = provideInterface,
+ args = (name, layer, ILayer, _context.info)
)
def skin(_context, name, layers):
- if ',' in ''.join(layers):
- raise TypeError("Commas are not allowed in layer names.")
+ skin = InterfaceClass(name, layers,
+ __doc__='Skin: %s' %name,
+ __module__='zope.app.skins')
+
+ # Register the layer interface as an interface
+ # Note: We have to do this immediately, so that directives using the
+ # InterfaceField can find the layer.
_context.action(
+ discriminator = ('interface', 'zope.app.skins.'+name),
+ callable = provideInterface,
+ args = ('zope.app.skins.'+name, skin),
+ kw = {'info': _context.info}
+ )
+
+ # Register the layer interface as a layer
+ _context.action(
discriminator = ('skin', name),
- callable = handler,
- args = (Presentation, 'defineSkin', name, layers, _context.info)
+ callable = provideInterface,
+ args = (name, skin, ISkin, _context.info)
)
+def setDefaultSkin(name, info):
+ # XXX: Test
+ skin = zapi.getUtility(ISkin, name)
+ handler('Adapters', 'register',
+ (IBrowserRequest,), IDefaultSkin, '', skin, info),
+
def defaultSkin(_context, name):
+
_context.action(
discriminator = 'defaultSkin',
- callable = handler,
- args = (Presentation, 'setDefaultSkin', name, _context.info)
+ callable = setDefaultSkin,
+ args = (name, _context.info)
)
def defaultView(_context, name, for_=None):
@@ -63,8 +118,8 @@
_context.action(
discriminator = ('defaultViewName', for_, type, name),
callable = handler,
- args = (zapi.servicenames.Presentation,
- 'setDefaultViewName', for_, type, name),
+ args = (zapi.servicenames.Adapters, 'register',
+ (for_, type), IDefaultViewName, '', name, _context.info)
)
if for_ is not None:
Modified: Zope3/trunk/src/zope/app/publisher/browser/resourcemeta.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/resourcemeta.py 2004-09-17 16:15:52 UTC (rev 27577)
+++ Zope3/trunk/src/zope/app/publisher/browser/resourcemeta.py 2004-09-17 16:15:54 UTC (rev 27578)
@@ -17,10 +17,12 @@
"""
import os
-from zope.app import zapi
-from zope.security.checker import CheckerPublic, NamesChecker
from zope.configuration.exceptions import ConfigurationError
+from zope.interface import Interface
from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.security.checker import CheckerPublic, NamesChecker
+
+from zope.app import zapi
from zope.app.component.metaconfigure import handler
from fileresource import FileResourceFactory, ImageResourceFactory
@@ -30,7 +32,7 @@
allowed_names = ('GET', 'HEAD', 'publishTraverse', 'browserDefault',
'request', '__call__')
-def resource(_context, name, layer='default', permission='zope.Public',
+def resource(_context, name, layer=IBrowserRequest, permission='zope.Public',
file=None, image=None, template=None):
if permission == 'zope.Public':
@@ -55,11 +57,11 @@
_context.action(
discriminator = ('resource', name, IBrowserRequest, layer),
callable = handler,
- args = (zapi.servicenames.Presentation, 'provideResource',
- name, IBrowserRequest, factory, layer),
+ args = (zapi.servicenames.Adapters, 'register',
+ (layer,), Interface, name, factory, _context.info),
)
-def resourceDirectory(_context, name, directory, layer='default',
+def resourceDirectory(_context, name, directory, layer=IBrowserRequest,
permission='zope.Public'):
if permission == 'zope.Public':
permission = CheckerPublic
@@ -76,6 +78,6 @@
_context.action(
discriminator = ('resource', name, IBrowserRequest, layer),
callable = handler,
- args = (zapi.servicenames.Presentation, 'provideResource',
- name, IBrowserRequest, factory, layer),
+ args = (zapi.servicenames.Adapters, 'register',
+ (layer,), Interface, name, factory, _context.info),
)
Modified: Zope3/trunk/src/zope/app/publisher/browser/resources.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/resources.py 2004-09-17 16:15:52 UTC (rev 27577)
+++ Zope3/trunk/src/zope/app/publisher/browser/resources.py 2004-09-17 16:15:54 UTC (rev 27578)
@@ -22,7 +22,6 @@
from zope.app import zapi
from zope.app.location import locate
-from zope.app.servicenames import Presentation
class Resources(BrowserView):
"""Provide a URL-accessible resource namespace
@@ -33,12 +32,12 @@
def publishTraverse(self, request, name):
'''See interface IBrowserPublisher'''
- resource_service = zapi.getService(Presentation)
- resource = resource_service.queryResource(name, request)
+ resource = zapi.queryResource(name, request)
if resource is None:
raise NotFoundError(self, name)
- locate(resource, resource_service, name)
+ adapters = zapi.getService(zapi.servicenames.Adapters)
+ locate(resource, adapters, name)
return resource
def browserDefault(self, request):
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py 2004-09-17 16:15:52 UTC (rev 27577)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_directives.py 2004-09-17 16:15:54 UTC (rev 27578)
@@ -19,13 +19,11 @@
import unittest
from cStringIO import StringIO
-from zope.interface import Interface, implements
+from zope.interface import Interface, implements, directlyProvides, providedBy
from zope.configuration.xmlconfig import xmlconfig, XMLConfig
from zope.configuration.exceptions import ConfigurationError
from zope.app.component.tests.views import IC, V1, VZMI, R1, IV
-from zope.component import getView, queryView, queryResource
-from zope.component import getDefaultViewName, getResource
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.security.proxy import ProxyFactory
import zope.security.management
@@ -42,6 +40,8 @@
from zope.component.service import serviceManager
from zope.publisher.interfaces.browser import IBrowserPublisher
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.publisher.interfaces.browser import ISkin, IDefaultSkin
from zope.app import zapi
from zope.app.tests import ztapi
from zope.app.traversing.adapters import DefaultTraversable
@@ -98,15 +98,12 @@
def setUp(self):
super(Test, self).setUp()
-
XMLConfig('meta.zcml', zope.app.publisher.browser)()
-
ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
- ps = zapi.getGlobalService(zapi.servicenames.Presentation)
def testPage(self):
- self.assertEqual(queryView(ob, 'test', request),
+ self.assertEqual(zapi.queryView(ob, 'test', request),
None)
xmlconfig(StringIO(template % (
@@ -121,11 +118,11 @@
'''
)))
- v = queryView(ob, 'test', request)
+ v = zapi.queryView(ob, 'test', request)
self.assert_(issubclass(v.__class__, V1))
def testPageWithClassWithMenu(self):
- self.assertEqual(queryView(ob, 'test', request),
+ self.assertEqual(zapi.queryView(ob, 'test', request),
None)
testtemplate = os.path.join(tests_path, 'testfiles', 'test.pt')
@@ -150,12 +147,12 @@
'test_menu', ob, TestRequest())
self.assertEqual(menuItem["title"], "Test View")
self.assertEqual(menuItem["action"], "@@test")
- v = queryView(ob, 'test', request)
+ v = zapi.queryView(ob, 'test', request)
self.assertEqual(v(), "<html><body><p>test</p></body></html>\n")
def testPageWithTemplateWithMenu(self):
- self.assertEqual(queryView(ob, 'test', request),
+ self.assertEqual(zapi.queryView(ob, 'test', request),
None)
testtemplate = os.path.join(tests_path, 'testfiles', 'test.pt')
@@ -178,12 +175,12 @@
'test_menu', ob, TestRequest())
self.assertEqual(menuItem["title"], "Test View")
self.assertEqual(menuItem["action"], "@@test")
- v = queryView(ob, 'test', request)
+ v = zapi.queryView(ob, 'test', request)
self.assertEqual(v(), "<html><body><p>test</p></body></html>\n")
def testPageInPagesWithTemplateWithMenu(self):
- self.assertEqual(queryView(ob, 'test', request),
+ self.assertEqual(zapi.queryView(ob, 'test', request),
None)
testtemplate = os.path.join(tests_path, 'testfiles', 'test.pt')
@@ -208,12 +205,12 @@
'test_menu', ob, TestRequest())
self.assertEqual(menuItem["title"], "Test View")
self.assertEqual(menuItem["action"], "@@test")
- v = queryView(ob, 'test', request)
+ v = zapi.queryView(ob, 'test', request)
self.assertEqual(v(), "<html><body><p>test</p></body></html>\n")
def testPageInPagesWithClassWithMenu(self):
- self.assertEqual(queryView(ob, 'test', request),
+ self.assertEqual(zapi.queryView(ob, 'test', request),
None)
testtemplate = os.path.join(tests_path, 'testfiles', 'test.pt')
@@ -240,11 +237,11 @@
'test_menu', ob, TestRequest())
self.assertEqual(menuItem["title"], "Test View")
self.assertEqual(menuItem["action"], "@@test")
- v = queryView(ob, 'test', request)
+ v = zapi.queryView(ob, 'test', request)
self.assertEqual(v(), "<html><body><p>test</p></body></html>\n")
def testDefaultView(self):
- self.assertEqual(queryView(ob, 'test', request,
+ self.assertEqual(zapi.queryView(ob, 'test', request,
None), None)
xmlconfig(StringIO(template % (
@@ -255,7 +252,7 @@
'''
)))
- self.assertEqual(getDefaultViewName(ob, request
+ self.assertEqual(zapi.getDefaultViewName(ob, request
), 'test')
def testSkinResource(self):
@@ -265,7 +262,7 @@
xmlconfig(StringIO(template % (
'''
<browser:layer name="zmi" />
- <browser:skin name="zmi" layers="zmi default" />
+ <browser:skin name="zmi" layers="zmi" />
<browser:resource
name="test"
factory="zope.app.component.tests.views.RZMI"
@@ -278,16 +275,19 @@
self.assertEqual(
zapi.queryResource('test', request, None).__class__, R1)
+ zmi = zapi.getUtility(ISkin, 'zmi')
self.assertEqual(
- zapi.queryResource('test', TestRequest(skin='zmi'), None).__class__,
+ zapi.queryResource('test', TestRequest(skin=zmi), None).__class__,
RZMI)
def testDefaultSkin(self):
- self.assertEqual(queryView(ob, 'test', request, None), None)
+ request = TestRequest()
+
+ self.assertEqual(zapi.queryView(ob, 'test', request, None), None)
xmlconfig(StringIO(template % (
'''
<browser:layer name="zmi" />
- <browser:skin name="zmi" layers="zmi default" />
+ <browser:skin name="zmi" layers="zmi" />
<browser:defaultSkin name="zmi" />
<browser:page name="test"
class="zope.app.component.tests.views.VZMI"
@@ -304,16 +304,22 @@
/>
'''
)))
- v = queryView(ob, 'test', TestRequest(skin=''))
+
+ # Simulate Zope Publication behavior in beforeTraversal()
+ adapters = zapi.getService(zapi.servicenames.Adapters)
+ skin = adapters.lookup((providedBy(request),), IDefaultSkin, '')
+ directlyProvides(request, skin)
+
+ v = zapi.queryView(ob, 'test', request)
self.assert_(issubclass(v.__class__, VZMI))
def testSkinPage(self):
- self.assertEqual(queryView(ob, 'test', request, None), None)
+ self.assertEqual(zapi.queryView(ob, 'test', request, None), None)
xmlconfig(StringIO(template % (
'''
<browser:layer name="zmi" />
- <browser:skin name="zmi" layers="zmi default" />
+ <browser:skin name="zmi" layers="zmi" />
<browser:page name="test"
class="zope.app.component.tests.views.VZMI"
layer="zmi"
@@ -330,13 +336,14 @@
'''
)))
- v = queryView(ob, 'test', request)
+ v = zapi.queryView(ob, 'test', request)
self.assert_(issubclass(v.__class__, V1))
- v = queryView(ob, 'test', TestRequest(skin='zmi'))
+ zmi = zapi.getUtility(ISkin, 'zmi')
+ v = zapi.queryView(ob, 'test', TestRequest(skin=zmi))
self.assert_(issubclass(v.__class__, VZMI))
def testI18nResource(self):
- self.assertEqual(queryResource('test', request, None), None)
+ self.assertEqual(zapi.queryResource('test', request, None), None)
path1 = os.path.join(tests_path, 'testfiles', 'test.pt')
path2 = os.path.join(tests_path, 'testfiles', 'test2.pt')
@@ -350,9 +357,9 @@
''' % (path1, path2)
)))
- v = getResource('test', request)
+ v = zapi.getResource('test', request)
self.assertEqual(
- queryResource('test', request).__class__,
+ zapi.queryResource('test', request).__class__,
I18nFileResource)
self.assertEqual(v._testData('en'), open(path1, 'rb').read())
self.assertEqual(v._testData('fr'), open(path2, 'rb').read())
@@ -392,7 +399,7 @@
'''
))
- v = getView(ob, 'test', request)
+ v = zapi.getView(ob, 'test', request)
v = ProxyFactory(v)
self.assertEqual(v.index(), 'V1 here')
self.assertRaises(Exception, getattr, v, 'action')
@@ -410,7 +417,7 @@
'''
))
- v = getView(ob, 'test', request)
+ v = zapi.getView(ob, 'test', request)
v = ProxyFactory(v)
self.assertEqual(v.action(), 'done')
self.assertRaises(Exception, getattr, v, 'index')
@@ -429,7 +436,7 @@
'''
))
- v = getView(ob, 'test', request)
+ v = zapi.getView(ob, 'test', request)
self.assertEqual(v.index(), 'V1 here')
self.assertEqual(v.action(), 'done')
@@ -447,7 +454,7 @@
'''
))
- v = getView(ob, 'test', request)
+ v = zapi.getView(ob, 'test', request)
self.assertEqual(v.index(), 'V1 here')
self.assertEqual(v.action(), 'done')
@@ -465,7 +472,7 @@
'''
))
- v = getView(ob, 'test', request)
+ v = zapi.getView(ob, 'test', request)
self.assertEqual(v.index(), v)
self.assert_(IBrowserPublisher.providedBy(v))
@@ -486,7 +493,7 @@
def testPageViews(self):
- self.assertEqual(queryView(ob, 'test', request), None)
+ self.assertEqual(zapi.queryView(ob, 'test', request), None)
test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')
xmlconfig(StringIO(template %
@@ -504,15 +511,15 @@
''' % test3
))
- v = getView(ob, 'index.html', request)
+ v = zapi.getView(ob, 'index.html', request)
self.assertEqual(v(), 'V1 here')
- v = getView(ob, 'action.html', request)
+ v = zapi.getView(ob, 'action.html', request)
self.assertEqual(v(), 'done')
- v = getView(ob, 'test.html', request)
+ v = zapi.getView(ob, 'test.html', request)
self.assertEqual(str(v()), '<html><body><p>done</p></body></html>\n')
def testNamedViewPageViewsCustomTraversr(self):
- self.assertEqual(queryView(ob, 'test', request), None)
+ self.assertEqual(zapi.queryView(ob, 'test', request), None)
xmlconfig(StringIO(template %
'''
@@ -529,7 +536,7 @@
'''
))
- view = getView(ob, 'test', request)
+ view = zapi.getView(ob, 'test', request)
view = removeSecurityProxy(view)
self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))
@@ -543,7 +550,7 @@
def testNamedViewNoPagesForCallable(self):
- self.assertEqual(queryView(ob, 'test', request), None)
+ self.assertEqual(zapi.queryView(ob, 'test', request), None)
xmlconfig(StringIO(template %
'''
@@ -556,12 +563,12 @@
'''
))
- view = getView(ob, 'test', request)
+ view = zapi.getView(ob, 'test', request)
view = removeSecurityProxy(view)
self.assertEqual(view.browserDefault(request), (view, ()))
def testNamedViewNoPagesForNonCallable(self):
- self.assertEqual(queryView(ob, 'test', request), None)
+ self.assertEqual(zapi.queryView(ob, 'test', request), None)
xmlconfig(StringIO(template %
'''
@@ -574,12 +581,12 @@
'''
))
- view = getView(ob, 'test', request)
+ view = zapi.getView(ob, 'test', request)
view = removeSecurityProxy(view)
self.assertEqual(getattr(view, 'browserDefault', None), None)
def testNamedViewPageViewsNoDefault(self):
- self.assertEqual(queryView(ob, 'test', request), None)
+ self.assertEqual(zapi.queryView(ob, 'test', request), None)
test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')
xmlconfig(StringIO(template %
@@ -598,7 +605,7 @@
''' % test3
))
- view = getView(ob, 'test', request)
+ view = zapi.getView(ob, 'test', request)
view = removeSecurityProxy(view)
self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))
@@ -614,7 +621,7 @@
self.assertEqual(str(v()), '<html><body><p>done</p></body></html>\n')
def testNamedViewPageViewsWithDefault(self):
- self.assertEqual(queryView(ob, 'test', request), None)
+ self.assertEqual(zapi.queryView(ob, 'test', request), None)
test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')
xmlconfig(StringIO(template %
@@ -634,7 +641,7 @@
''' % test3
))
- view = getView(ob, 'test', request)
+ view = zapi.getView(ob, 'test', request)
view = removeSecurityProxy(view)
self.assertEqual(view.browserDefault(request)[1], (u'test.html', ))
@@ -667,7 +674,7 @@
'''
))
- view = getView(ob, 'test', request)
+ view = zapi.getView(ob, 'test', request)
view = removeSecurityProxy(view)
view.publishTraverse(request, 'index.html')
@@ -694,7 +701,7 @@
'''
))
- view = getView(ob, 'test', request)
+ view = zapi.getView(ob, 'test', request)
view = removeSecurityProxy(view)
view.publishTraverse(request, 'index.html')
@@ -702,7 +709,7 @@
ztapi.provideUtility(IPermission, Permission('p', 'P'), 'p')
request = TestRequest()
- self.assertEqual(queryView(ob, 'test', request),
+ self.assertEqual(zapi.queryView(ob, 'test', request),
None)
xmlconfig(StringIO(template %
@@ -723,16 +730,16 @@
'''
))
- v = getView(ob, 'index.html', request)
+ v = zapi.getView(ob, 'index.html', request)
v = ProxyFactory(v)
zope.security.management.getInteraction().add(request)
self.assertRaises(Exception, v)
- v = getView(ob, 'action.html', request)
+ v = zapi.getView(ob, 'action.html', request)
v = ProxyFactory(v)
self.assertRaises(Exception, v)
def testProtectedNamedViewPageViews(self):
- self.assertEqual(queryView(ob, 'test', request),
+ self.assertEqual(zapi.queryView(ob, 'test', request),
None)
xmlconfig(StringIO(template %
@@ -754,19 +761,19 @@
'''
))
- view = getView(ob, 'test', request)
+ view = zapi.getView(ob, 'test', request)
self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))
v = view.publishTraverse(request, 'index.html')
self.assertEqual(v(), 'V1 here')
def testSkinnedPageView(self):
- self.assertEqual(queryView(ob, 'test', request), None)
+ self.assertEqual(zapi.queryView(ob, 'test', request), None)
xmlconfig(StringIO(template %
'''
<browser:layer name="layer" />
- <browser:skin name="skinny" layers="layer default" />
+ <browser:skin name="skinny" layers="layer" />
<browser:pages
for="*"
class="zope.app.component.tests.views.V1"
@@ -787,15 +794,16 @@
'''
))
- v = getView(ob, 'index.html', request)
+ v = zapi.getView(ob, 'index.html', request)
self.assertEqual(v(), 'V1 here')
- v = getView(ob, 'index.html', TestRequest(skin="skinny"))
+ skinny = zapi.getUtility(ISkin, 'skinny')
+ v = zapi.getView(ob, 'index.html', TestRequest(skin=skinny))
self.assertEqual(v(), 'done')
def testFile(self):
path = os.path.join(tests_path, 'testfiles', 'test.pt')
- self.assertEqual(queryResource('test', request), None)
+ self.assertEqual(zapi.queryResource('test', request), None)
xmlconfig(StringIO(template %
'''
@@ -806,7 +814,7 @@
''' % path
))
- r = getResource('index.html', request)
+ r = zapi.getResource('index.html', request)
self.assertEquals(r.__class__, FileResource)
r = ProxyFactory(r)
self.assertEqual(r.__name__, "index.html")
@@ -825,7 +833,7 @@
def testSkinResource(self):
self.assertEqual(
- queryResource('test', request, None),
+ zapi.queryResource('test', request, None),
None)
path = os.path.join(tests_path, 'testfiles', 'test.pt')
@@ -833,22 +841,23 @@
xmlconfig(StringIO(template % (
'''
<browser:layer name="zmi" />
- <browser:skin name="zmi" layers="zmi default" />
+ <browser:skin name="zmi" layers="zmi" />
<browser:resource name="test" file="%s"
layer="zmi" />
''' % path
)))
- self.assertEqual(queryResource('test', request), None)
+ self.assertEqual(zapi.queryResource('test', request), None)
- r = getResource('test', TestRequest(skin='zmi'))
+ zmi = zapi.getUtility(ISkin, 'zmi')
+ r = zapi.getResource('test', TestRequest(skin=zmi))
r = removeSecurityProxy(r)
self.assertEqual(r._testData(), open(path, 'rb').read())
def test_template_page(self):
path = os.path.join(tests_path, 'testfiles', 'test.pt')
- self.assertEqual(queryView(ob, 'index.html', request),
+ self.assertEqual(zapi.queryView(ob, 'index.html', request),
None)
xmlconfig(StringIO(template %
@@ -861,13 +870,13 @@
''' % path
))
- v = getView(ob, 'index.html', request)
+ v = zapi.getView(ob, 'index.html', request)
self.assertEqual(v().strip(), '<html><body><p>test</p></body></html>')
def testtemplateWClass(self):
path = os.path.join(tests_path, 'testfiles', 'test2.pt')
- self.assertEqual(queryView(ob, 'index.html', request),
+ self.assertEqual(zapi.queryView(ob, 'index.html', request),
None)
xmlconfig(StringIO(template %
@@ -881,7 +890,7 @@
''' % path
))
- v = getView(ob, 'index.html', request)
+ v = zapi.getView(ob, 'index.html', request)
self.assertEqual(v().strip(), '<html><body><p>42</p></body></html>')
def testProtectedtemplate(self):
@@ -889,7 +898,7 @@
path = os.path.join(tests_path, 'testfiles', 'test.pt')
request = TestRequest()
- self.assertEqual(queryView(ob, 'test', request),
+ self.assertEqual(zapi.queryView(ob, 'test', request),
None)
xmlconfig(StringIO(template %
@@ -916,12 +925,12 @@
''' % path
))
- v = getView(ob, 'xxx.html', request)
+ v = zapi.getView(ob, 'xxx.html', request)
v = ProxyFactory(v)
zope.security.management.getInteraction().add(request)
self.assertRaises(Exception, v)
- v = getView(ob, 'index.html', request)
+ v = zapi.getView(ob, 'index.html', request)
v = ProxyFactory(v)
self.assertEqual(v().strip(), '<html><body><p>test</p></body></html>')
@@ -960,7 +969,7 @@
def testViewThatProvidesAnInterface(self):
request = TestRequest()
- self.assertEqual(queryView(ob, 'test', request, None), None)
+ self.assertEqual(zapi.queryView(ob, 'test', request, None), None)
xmlconfig(StringIO(template %
'''
@@ -973,7 +982,7 @@
'''
))
- v = queryView(ob, 'test', request, None, providing=IV)
+ v = zapi.queryView(ob, 'test', request, providing=IV)
self.assertEqual(v, None)
xmlconfig(StringIO(template %
@@ -988,13 +997,13 @@
'''
))
- v = queryView(ob, 'test', request, None, providing=IV)
-
+ v = zapi.queryView(ob, 'test', request, providing=IV)
self.assert_(isinstance(v, V1))
def testUnnamedViewThatProvidesAnInterface(self):
request = TestRequest()
- self.assertEqual(queryView(ob, '', request, None, providing=IV), None)
+ self.assertEqual(zapi.queryView(ob, '', request, None, providing=IV),
+ None)
xmlconfig(StringIO(template %
'''
@@ -1006,7 +1015,7 @@
'''
))
- v = queryView(ob, '', request, None, providing=IV)
+ v = zapi.queryView(ob, '', request, None, providing=IV)
self.assertEqual(v, None)
xmlconfig(StringIO(template %
@@ -1020,7 +1029,7 @@
'''
))
- v = queryView(ob, '', request, None, providing=IV)
+ v = zapi.queryView(ob, '', request, None, providing=IV)
self.assert_(isinstance(v, V1))
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_icondirective.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_icondirective.py 2004-09-17 16:15:52 UTC (rev 27577)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_icondirective.py 2004-09-17 16:15:54 UTC (rev 27578)
@@ -19,17 +19,16 @@
from StringIO import StringIO
from unittest import TestCase, main, makeSuite
-from zope.component import queryView, getView, getResource
from zope.configuration.exceptions import ConfigurationError
from zope.configuration.xmlconfig import xmlconfig, XMLConfig
from zope.interface import implements
-from zope.security.proxy import removeSecurityProxy
from zope.publisher.browser import TestRequest
from zope.security.checker import ProxyFactory, CheckerPublic
from zope.security.interfaces import Forbidden
+from zope.security.proxy import removeSecurityProxy
import zope.app.publisher.browser
-
+from zope.app import zapi
from zope.app.component.tests.views import IC
from zope.app.site.interfaces import ISite
from zope.app.publisher.browser.tests import support
@@ -67,23 +66,23 @@
super(Test, self).setUp()
XMLConfig('meta.zcml', zope.app.publisher.browser)()
defineCheckers()
-
+
def test(self):
- self.assertEqual(queryView(ob, 'zmi_icon', request), None)
+ self.assertEqual(zapi.queryView(ob, 'zmi_icon', request), None)
import zope.app.publisher.browser.tests as p
path = os.path.dirname(p.__file__)
path = os.path.join(path, 'testfiles', 'test.gif')
xmlconfig(StringIO(template % (
- """
+ '''
<browser:icon name="zmi_icon"
for="zope.app.component.tests.views.IC"
file="%s" />
- """ % path
+ ''' % path
)))
- view = getView(ob, 'zmi_icon', request)
+ view = zapi.getView(ob, 'zmi_icon', request)
rname = 'zope-app-component-tests-views-IC-zmi_icon.gif'
self.assertEqual(
view(),
@@ -91,29 +90,29 @@
'width="16" height="16" border="0" />'
% rname)
- resource = ProxyFactory(getResource(rname, request))
+ resource = ProxyFactory(zapi.getResource(rname, request))
self.assertRaises(Forbidden, getattr, resource, '_testData')
resource = removeSecurityProxy(resource)
self.assertEqual(resource._testData(), open(path, 'rb').read())
def testResource(self):
- self.assertEqual(queryView(ob, 'zmi_icon', request), None)
+ self.assertEqual(zapi.queryView(ob, 'zmi_icon', request), None)
import zope.app.publisher.browser.tests as p
path = os.path.dirname(p.__file__)
path = os.path.join(path, 'testfiles', 'test.gif')
xmlconfig(StringIO(template % (
- """
+ '''
<browser:resource name="zmi_icon_res"
image="%s" />
<browser:icon name="zmi_icon"
for="zope.app.component.tests.views.IC"
resource="zmi_icon_res" />
- """ % path
+ ''' % path
)))
- view = getView(ob, 'zmi_icon', request)
+ view = zapi.getView(ob, 'zmi_icon', request)
rname = "zmi_icon_res"
self.assertEqual(
view(),
@@ -121,28 +120,28 @@
'height="16" border="0" />'
% rname)
- resource = ProxyFactory(getResource(rname, request))
+ resource = ProxyFactory(zapi.getResource(rname, request))
self.assertRaises(Forbidden, getattr, resource, '_testData')
resource = removeSecurityProxy(resource)
self.assertEqual(resource._testData(), open(path, 'rb').read())
def testResourceErrors(self):
- self.assertEqual(queryView(ob, 'zmi_icon', request), None)
+ self.assertEqual(zapi.queryView(ob, 'zmi_icon', request), None)
import zope.app.publisher.browser.tests as p
path = os.path.dirname(p.__file__)
path = os.path.join(path, 'testfiles', 'test.gif')
config = StringIO(template % (
- """
+ '''
<browser:resource name="zmi_icon_res"
image="%s" />
<browser:icon name="zmi_icon"
for="zope.app.component.tests.views.IC"
file="%s"
resource="zmi_icon_res" />
- """ % (path, path)
+ ''' % (path, path)
))
self.assertRaises(ConfigurationError, xmlconfig, config)
Modified: Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py 2004-09-17 16:15:52 UTC (rev 27577)
+++ Zope3/trunk/src/zope/app/publisher/browser/viewmeta.py 2004-09-17 16:15:54 UTC (rev 27578)
@@ -18,6 +18,7 @@
import os
from zope.component.exceptions import ComponentLookupError
+from zope.component.interfaces import IDefaultViewName
from zope.interface import implements, classImplements, Interface
from zope.exceptions import NotFoundError
from zope.security.checker import CheckerPublic, Checker
@@ -88,16 +89,11 @@
# page
def page(_context, name, permission, for_,
- layer='default', template=None, class_=None,
+ layer=IBrowserRequest, template=None, class_=None,
allowed_interface=None, allowed_attributes=None,
attribute='__call__', menu=None, title=None,
):
- try:
- s = zapi.getGlobalService(zapi.servicenames.Presentation)
- except ComponentLookupError, err:
- pass
-
_handle_menu(_context, menu, title, [for_], name, permission)
required = {}
@@ -168,9 +164,8 @@
_context.action(
discriminator = ('view', for_, name, IBrowserRequest, layer),
callable = handler,
- args = (zapi.servicenames.Presentation, 'provideAdapter',
- IBrowserRequest, new_class, name, [for_], Interface, layer,
- _context.info),
+ args = (zapi.servicenames.Adapters, 'register',
+ (for_, layer), Interface, name, new_class, _context.info),
)
@@ -182,7 +177,7 @@
class pages(object):
def __init__(self, _context, for_, permission,
- layer='default', class_=None,
+ layer=IBrowserRequest, class_=None,
allowed_interface=None, allowed_attributes=None,
):
self.opts = dict(for_=for_, permission=permission,
@@ -213,7 +208,7 @@
default = None
def __init__(self, _context, for_, permission,
- name='', layer='default', class_=None,
+ name='', layer=IBrowserRequest, class_=None,
allowed_interface=None, allowed_attributes=None,
menu=None, title=None, provides=Interface,
):
@@ -256,10 +251,6 @@
pages = {}
for pname, attribute, template in self.pages:
- try:
- s = zapi.getGlobalService(zapi.servicenames.Presentation)
- except ComponentLookupError, err:
- pass
if template:
cdict[pname] = ViewPageTemplateFile(template)
@@ -350,13 +341,13 @@
discriminator = ('view', for_, name, IBrowserRequest, layer,
self.provides),
callable = handler,
- args = (zapi.servicenames.Presentation, 'provideAdapter',
- IBrowserRequest, newclass, name, [for_], self.provides,
- layer, _context.info),
+ args = (zapi.servicenames.Adapters, 'register',
+ (for_, layer), self.provides, name, newclass,
+ _context.info),
)
def addview(_context, name, permission,
- layer='default', class_=None,
+ layer=IBrowserRequest, class_=None,
allowed_interface=None, allowed_attributes=None,
menu=None, title=None
):
@@ -373,9 +364,9 @@
_context.action(
discriminator = ('defaultViewName', for_, IBrowserRequest, name),
callable = handler,
- args = (zapi.servicenames.Presentation,'setDefaultViewName',
- for_, IBrowserRequest,
- name),
+ args = (zapi.servicenames.Presentation.Adapters, 'register',
+ (for_, IBrowserRequest), IDefaultViewName, '', name,
+ _context.info)
)
if for_ is not None:
Modified: Zope3/trunk/src/zope/app/publisher/xmlrpc/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/xmlrpc/metaconfigure.py 2004-09-17 16:15:52 UTC (rev 27577)
+++ Zope3/trunk/src/zope/app/publisher/xmlrpc/metaconfigure.py 2004-09-17 16:15:54 UTC (rev 27578)
@@ -16,11 +16,12 @@
$Id$
"""
import zope.interface
+from zope.interface import Interface
from zope.security.checker import CheckerPublic, Checker
-from zope.component.servicenames import Presentation
from zope.configuration.exceptions import ConfigurationError
from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
+from zope.app import zapi
from zope.app.location import Location
from zope.app.component.interface import provideInterface
from zope.app.component.metaconfigure import handler
@@ -68,8 +69,10 @@
_context.action(
discriminator = ('view', for_, name, IXMLRPCRequest),
callable = handler,
- args = (Presentation, 'provideAdapter', IXMLRPCRequest, class_,
- name, (for_, )) )
+ args = (zapi.servicenames.Adapters, 'register',
+ (for_, IXMLRPCRequest), Interface, name, class_,
+ _context.info)
+ )
else:
if permission:
checker = Checker({'__call__': permission})
@@ -86,8 +89,10 @@
_context.action(
discriminator = ('view', for_, name, IXMLRPCRequest),
callable = handler,
- args = (Presentation, 'provideAdapter', IXMLRPCRequest,
- new_class, name, (for_, )) )
+ args = (zapi.servicenames.Adapters, 'register',
+ (for_, IXMLRPCRequest), Interface, name, new_class,
+ _context.info)
+ )
# Register the used interfaces with the interface service
if for_ is not None:
More information about the Zope3-Checkins
mailing list