[Checkins] SVN: z3.themehook/trunk/ Initial import.
Lennart Regebro
regebro at gmail.com
Sat Sep 29 10:04:11 EDT 2007
Log message for revision 80389:
Initial import.
Changed:
A z3.themehook/trunk/
A z3.themehook/trunk/README.txt
A z3.themehook/trunk/setup.cfg
A z3.themehook/trunk/setup.py
A z3.themehook/trunk/z3c/
A z3.themehook/trunk/z3c/__init__.py
A z3.themehook/trunk/z3c/themehook/
A z3.themehook/trunk/z3c/themehook/__init__.py
A z3.themehook/trunk/z3c/themehook/configure.zcml
A z3.themehook/trunk/z3c/themehook/interfaces.py
A z3.themehook/trunk/z3c/themehook/publication.py
A z3.themehook/trunk/z3c/themehook/tests/
A z3.themehook/trunk/z3c/themehook/tests/__init__.py
A z3.themehook/trunk/z3c/themehook/tests/ftesting.zcml
A z3.themehook/trunk/z3c/themehook/tests/test_themehook.py
-=-
Added: z3.themehook/trunk/README.txt
===================================================================
--- z3.themehook/trunk/README.txt (rev 0)
+++ z3.themehook/trunk/README.txt 2007-09-29 14:04:11 UTC (rev 80389)
@@ -0,0 +1,18 @@
+z3c.themehook Package Readme
+============================
+
+Overview
+--------
+This package contains a publication object that provides a hook for callObject,
+so that the calling gets pluggable. The main reason for this is to apply
+theming, which is why the module is called "themehook".
+
+Usage
+-----
+A themehook is a multiadapter between (None, IBrowserRequest) and
+z3c.themehook.interfaces.IPublicationObjectCaller. An example can be found
+in z3c.themehook.publication.DefaultPublicationObjectCaller which simply
+does what Zope 3s default publication object does.
+
+All you need to do to use the themehook is to create a new such adapter
+and register it, and it will be automatically used for the whole application.
Property changes on: z3.themehook/trunk/README.txt
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3.themehook/trunk/setup.cfg
===================================================================
--- z3.themehook/trunk/setup.cfg (rev 0)
+++ z3.themehook/trunk/setup.cfg 2007-09-29 14:04:11 UTC (rev 80389)
@@ -0,0 +1,3 @@
+[egg_info]
+tag_build = dev
+tag_svn_revision = true
Added: z3.themehook/trunk/setup.py
===================================================================
--- z3.themehook/trunk/setup.py (rev 0)
+++ z3.themehook/trunk/setup.py 2007-09-29 14:04:11 UTC (rev 80389)
@@ -0,0 +1,30 @@
+from setuptools import setup, find_packages
+import sys, os
+
+version = '0.1'
+
+setup(name='z3c.themehook',
+ version=version,
+ description="Zope3 publication theme hook",
+ long_description="""z3c.themehook provides a publisher hook for theming mechanisms.""",
+ classifiers=[
+ 'Framework :: Zope3',
+ 'Programming Language :: Python',
+ 'License :: OSI Approved :: GNU General Public License (GPL)',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ ],
+ keywords='Zope3 theming',
+ author='Lennart Regebro',
+ author_email='regebro at gmail.com',
+ license='GPL',
+ packages=find_packages(exclude=['ez_setup']),
+ namespace_packages=['zope'],
+ include_package_data=True,
+ zip_safe=False,
+ install_requires=[
+ # -*- Extra requirements: -*-
+ ],
+ entry_points="""
+ # -*- Entry points: -*-
+ """,
+ )
Property changes on: z3.themehook/trunk/setup.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3.themehook/trunk/z3c/__init__.py
===================================================================
Property changes on: z3.themehook/trunk/z3c/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3.themehook/trunk/z3c/themehook/__init__.py
===================================================================
Property changes on: z3.themehook/trunk/z3c/themehook/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3.themehook/trunk/z3c/themehook/configure.zcml
===================================================================
--- z3.themehook/trunk/z3c/themehook/configure.zcml (rev 0)
+++ z3.themehook/trunk/z3c/themehook/configure.zcml 2007-09-29 14:04:11 UTC (rev 80389)
@@ -0,0 +1,15 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ xmlns:grok="http://namespaces.zope.org/grok"
+ i18n_domain="zope">
+
+ <publisher
+ name="BROWSER"
+ factory=".publication.PluggedBrowserFactory"
+ methods="GET POST HEAD"
+ mimetypes="*"
+ priority="12"
+ />
+
+</configure>
Property changes on: z3.themehook/trunk/z3c/themehook/configure.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3.themehook/trunk/z3c/themehook/interfaces.py
===================================================================
--- z3.themehook/trunk/z3c/themehook/interfaces.py (rev 0)
+++ z3.themehook/trunk/z3c/themehook/interfaces.py 2007-09-29 14:04:11 UTC (rev 80389)
@@ -0,0 +1,15 @@
+"""Interfaces
+"""
+
+from zope.interface import Interface
+
+class IPublicationObjectCaller(Interface):
+ """IPublicationCaller calls the object with the request
+
+ Calling IPublicationCaller should generate the output to be passed to
+ the publisher. An IPublicationCaller should be an adapter between
+ (ob, request) and IPublicationCaller."""
+
+ def __call__():
+ """calls the object"""
+
\ No newline at end of file
Property changes on: z3.themehook/trunk/z3c/themehook/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3.themehook/trunk/z3c/themehook/publication.py
===================================================================
--- z3.themehook/trunk/z3c/themehook/publication.py (rev 0)
+++ z3.themehook/trunk/z3c/themehook/publication.py 2007-09-29 14:04:11 UTC (rev 80389)
@@ -0,0 +1,40 @@
+import zope.interface
+import zope.component
+from zope.app.publication.requestpublicationfactories import BrowserFactory
+from zope.security.checker import selectChecker
+from zope.publisher.interfaces.browser import IBrowserRequest
+
+from zope.app.publication.browser import BrowserPublication
+from zope.publisher.publish import mapply
+
+from interfaces import IPublicationObjectCaller
+
+class PluggedBrowserPublication(BrowserPublication):
+
+ def callObject(self, request, ob):
+ adapter = zope.component.queryMultiAdapter((ob, request),
+ IPublicationObjectCaller)
+ if adapter is None:
+ # Fallback to a hook that just makes a mapply:
+ adapter = DefaultPublicationObjectCaller(ob, request)
+ return adapter()
+
+class PluggedBrowserFactory(BrowserFactory):
+
+ def __call__(self):
+ request, publication = super(PluggedBrowserFactory, self).__call__()
+ return request, PluggedBrowserPublication
+
+class DefaultPublicationObjectCaller(object):
+ zope.interface.implements(IPublicationObjectCaller)
+ zope.component.adapts(None, IBrowserRequest)
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ def __call__(self):
+ return mapply(self.context,
+ self.request.getPositionalArguments(),
+ self.request)
+
Property changes on: z3.themehook/trunk/z3c/themehook/publication.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3.themehook/trunk/z3c/themehook/tests/__init__.py
===================================================================
Property changes on: z3.themehook/trunk/z3c/themehook/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3.themehook/trunk/z3c/themehook/tests/ftesting.zcml
===================================================================
--- z3.themehook/trunk/z3c/themehook/tests/ftesting.zcml (rev 0)
+++ z3.themehook/trunk/z3c/themehook/tests/ftesting.zcml 2007-09-29 14:04:11 UTC (rev 80389)
@@ -0,0 +1,56 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta"
+ i18n_domain="">
+
+ <!-- Turn on the devmode -->
+ <meta:provides feature="devmode" />
+ <include package="zope.security" file="meta.zcml" />
+ <include package="zope.app.zcmlfiles" file="meta.zcml" />
+
+ <!--include package="zope.publisher" /-->
+ <include package="zope.app.zcmlfiles" />
+
+ <include package="z3c.themehook" />
+
+ <include package="zope.app.securitypolicy" file="meta.zcml" />
+ <include package="zope.app.securitypolicy" />
+ <securityPolicy
+ component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+
+ <!-- Test Principals -->
+
+ <unauthenticatedPrincipal id="zope.anybody"
+ title="Unauthenticated User" />
+ <unauthenticatedGroup id="zope.Anybody"
+ title="Unauthenticated Users" />
+ <authenticatedGroup id="zope.Authenticated"
+ title="Authenticated Users" />
+ <everybodyGroup id="zope.Everybody"
+ title="All Users" />
+
+ <!-- Principal that tests generally run as -->
+ <principal
+ id="zope.mgr"
+ title="Manager"
+ login="mgr"
+ password="mgrpw"
+ />
+ <!-- Bootstrap principal used to make local grant to the principal above -->
+ <principal
+ id="zope.globalmgr"
+ title="Manager"
+ login="globalmgr"
+ password="globalmgrpw"
+ />
+
+ <grant permission="zope.View"
+ principal="zope.Anybody" />
+ <grant permission="zope.app.dublincore.view"
+ principal="zope.Anybody" />
+
+ <role id="zope.Manager" title="Site Manager" />
+ <role id="zope.Member" title="Site Member" />
+ <grantAll role="zope.Manager" />
+ <grant role="zope.Manager" principal="zope.globalmgr" />
+
+</configure>
Property changes on: z3.themehook/trunk/z3c/themehook/tests/ftesting.zcml
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3.themehook/trunk/z3c/themehook/tests/test_themehook.py
===================================================================
--- z3.themehook/trunk/z3c/themehook/tests/test_themehook.py (rev 0)
+++ z3.themehook/trunk/z3c/themehook/tests/test_themehook.py 2007-09-29 14:04:11 UTC (rev 80389)
@@ -0,0 +1,56 @@
+import os
+import unittest
+import zope.interface
+import zope.component
+import zope.app.testing
+from zope.testbrowser.testing import Browser
+from zope.app.testing import functional
+
+from z3c.themehook.interfaces import IPublicationObjectCaller
+from zope.publisher.interfaces.browser import IBrowserRequest
+
+ThemeHookLayer = functional.ZCMLLayer(
+ os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
+ __name__, 'ThemeHookLayer', allow_teardown=True)
+
+class TestThemer(object):
+ zope.interface.implements(IPublicationObjectCaller)
+ zope.component.adapts(None, IBrowserRequest)
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ def __call__(self):
+ return 'TestThemer output'
+
+
+class ThemeHookTest(functional.FunctionalTestCase):
+ layer = ThemeHookLayer
+
+ def test_themehook(self):
+ # First test that things work with a hook
+ browser = Browser()
+ browser.open('http://localhost/')
+ # Make sure it worked
+ self.failUnless('Unauthenticated User' in browser.contents,
+ "Default caller broken")
+
+ # Register the themer in the hook:
+ zope.component.provideAdapter(TestThemer, (None, IBrowserRequest),
+ IPublicationObjectCaller)
+
+ # Now put in the theming:
+ browser.open('http://localhost/')
+ # Not it's the TestThemer that makes the output:
+ self.failUnless('TestThemer output' in browser.contents,
+ 'TestThemer output not found',)
+
+def test_suite():
+ from unittest import TestSuite, makeSuite
+
+ suite = TestSuite()
+ suite.addTests(makeSuite(ThemeHookTest))
+
+ return suite
+
Property changes on: z3.themehook/trunk/z3c/themehook/tests/test_themehook.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list