[z3-checkins] r22198 - in
z3/Five/branch/rocky-products-less-product-loading: . tests
rocky at codespeak.net
rocky at codespeak.net
Sun Jan 15 17:12:33 CET 2006
Author: rocky
Date: Sun Jan 15 17:11:46 2006
New Revision: 22198
Modified:
z3/Five/branch/rocky-products-less-product-loading/ (props changed)
z3/Five/branch/rocky-products-less-product-loading/__init__.py
z3/Five/branch/rocky-products-less-product-loading/fivedirectives.py
z3/Five/branch/rocky-products-less-product-loading/meta.zcml
z3/Five/branch/rocky-products-less-product-loading/pythonproducts.py
z3/Five/branch/rocky-products-less-product-loading/tests/test_pythonproducts.py
Log:
- Renamed registerProduct directive to registerPackage
- Added new optional initialize attribute to registerPackage directive
- Switched from PEP 8 naming conventions to be more consistent with existing Five code
Modified: z3/Five/branch/rocky-products-less-product-loading/__init__.py
==============================================================================
--- z3/Five/branch/rocky-products-less-product-loading/__init__.py (original)
+++ z3/Five/branch/rocky-products-less-product-loading/__init__.py Sun Jan 15 17:11:46 2006
@@ -27,6 +27,6 @@
from skin.standardmacros import StandardMacros
def initialize(context):
- pythonproducts.setup_python_products(context)
+ pythonproducts.setupPythonProducts(context)
zcml.load_site()
Modified: z3/Five/branch/rocky-products-less-product-loading/fivedirectives.py
==============================================================================
--- z3/Five/branch/rocky-products-less-product-loading/fivedirectives.py (original)
+++ z3/Five/branch/rocky-products-less-product-loading/fivedirectives.py Sun Jan 15 17:11:46 2006
@@ -179,9 +179,20 @@
u'particular product, no error is raised.',
required=False)
-class IRegisterProductDirective(Interface):
+class IRegisterPackageDirective(Interface):
+ """Registers the given python package which at a minimum fools zope2 into
+ thinking of it as a zope2 product.
+ """
package = GlobalObject(
- title=u"Target package",
+ title=u'Target package',
required=True
)
+
+ initialize = GlobalObject(
+ title=u'Initialization function to invoke',
+ description=u'The dotted name of a function that will get invoked '
+ u'with a ProductContext instance',
+ required=False
+ )
+
\ No newline at end of file
Modified: z3/Five/branch/rocky-products-less-product-loading/meta.zcml
==============================================================================
--- z3/Five/branch/rocky-products-less-product-loading/meta.zcml (original)
+++ z3/Five/branch/rocky-products-less-product-loading/meta.zcml Sun Jan 15 17:11:46 2006
@@ -158,9 +158,9 @@
/>
<meta:directive
- name="registerProduct"
- schema=".fivedirectives.IRegisterProductDirective"
- handler=".pythonproducts.registerProduct"
+ name="registerPackage"
+ schema=".fivedirectives.IRegisterPackageDirective"
+ handler=".pythonproducts.registerPackage"
/>
</meta:directives>
Modified: z3/Five/branch/rocky-products-less-product-loading/pythonproducts.py
==============================================================================
--- z3/Five/branch/rocky-products-less-product-loading/pythonproducts.py (original)
+++ z3/Five/branch/rocky-products-less-product-loading/pythonproducts.py Sun Jan 15 17:11:46 2006
@@ -17,7 +17,6 @@
$Id$
"""
__author__ = "Rocky Burt"
-__all__ = ('setup_python_products', 'register_python_product')
import os
import types
@@ -28,33 +27,24 @@
_zope_app = None
-def registerProduct(_context, package):
+def registerPackage(_context, package, initialize=None):
"""ZCML directive function for registering a python package product
"""
_context.action(
- discriminator = ('registerProduct', package),
- callable = register_python_product,
- args = (package,)
+ discriminator = ('registerPackage', package),
+ callable = _registerPackage,
+ args = (package,initialize)
)
-def register_python_product(package):
+def _registerPackage(module_, initFunc=None):
"""Registers the given python package as a Zope 2 style product
"""
- if isinstance(package, basestring):
- module_ = __import__(package)
- elif isinstance(package, types.ModuleType):
- module_ = package
- else:
- raise TypeError("The package argument must either be an instance of " \
- "basestring or types.ModuleType")
-
if not hasattr(module_, '__path__'):
raise ValueError("Registering a python package currently only " \
"supports filesystem based pure python packages")
-
product = initializeProduct(module_,
module_.__name__,
@@ -63,21 +53,21 @@
product.package_name = module_.__name__
- if hasattr(module_, 'initialize') and \
- hasattr(module_.initialize, '__call__'):
+ if initFunc is not None:
newContext = ProductContext(product, _zope_app, module_)
- module_.initialize(newContext)
+ initFunc(newContext)
+
-def setup_python_products(context):
+def setupPythonProducts(context):
"""Initialize the python-packages-as-products logic
"""
_zope_app = context._ProductContext__app
global _zope_app
- apply_patches(_zope_app)
+ applyPatches(_zope_app)
-def apply_patches(app):
+def applyPatches(app):
"""Apply necessary monkey patches to force Zope 2 to be capable of
handling "products" that are not necessarily located under the Products
package. Ultimately all functionality provided by these patches should
Modified: z3/Five/branch/rocky-products-less-product-loading/tests/test_pythonproducts.py
==============================================================================
--- z3/Five/branch/rocky-products-less-product-loading/tests/test_pythonproducts.py (original)
+++ z3/Five/branch/rocky-products-less-product-loading/tests/test_pythonproducts.py Sun Jan 15 17:11:46 2006
@@ -19,9 +19,9 @@
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
-def test_registerProduct():
+def test_registerPackage():
"""
- Testing registerProduct
+ Testing registerPackage
>>> from zope.app.testing.placelesssetup import setUp, tearDown
>>> setUp()
@@ -30,20 +30,7 @@
>>> import Products.Five.tests
>>> import Products.Five.tests.testing
>>> from Products.Five.tests.testing import zope2module
- >>> from Products.Five import pythonproducts
-
- Make sure registerProduct only handles appropriate types::
-
- >>> pythonproducts.register_python_product(None)
- Traceback (most recent call last):
- ...
- TypeError: The package argument must either be an instance of basestring or types.ModuleType
-
- >>> pythonproducts.register_python_product(zope2module)
- Traceback (most recent call last):
- ...
- ValueError: Registering a python package currently only supports filesystem based pure python packages
-
+ >>> from Products.Five import pythonproducts
Clean up:
More information about the z3-checkins
mailing list