[Zope3-checkins] CVS: Zope3/src/zope/modulealias - __init__.py:1.2 meta.zcml:1.2 metaconfigure.py:1.2 metadirectives.py:1.2

Chris McDonough chrism at plope.com
Wed Jan 14 17:56:07 EST 2004


Update of /cvs-repository/Zope3/src/zope/modulealias
In directory cvs.zope.org:/tmp/cvs-serv5558/src/zope/modulealias

Added Files:
	__init__.py meta.zcml metaconfigure.py metadirectives.py 
Log Message:
Merge security policy refactoring:

 - Moved all role- and grant-related functionality into
   zope.products.securitypolicy (and out of zope.app.security.grant).
   The zope.products.securitypolicy implementation is exactly
   the same as the old implementation; no changes were made
   to the actual mechanics of role-permission or principal-permission
   grants.  The only real difference is that all functionality
   that is the purview of what we want a security policy to have
   control of is now in that one place.

 - Created new modulealias directive which can be used to provide
   aliases to older modules (to not break existing ZODBs when
   module locations change).

 - Added minor feature: "make debug" launches a debug session in the
   spirit of Zope 2's "zopectl debug".
   


=== Zope3/src/zope/modulealias/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Jan 14 17:56:01 2004
+++ Zope3/src/zope/modulealias/__init__.py	Wed Jan 14 17:55:31 2004
@@ -0,0 +1 @@
+# Make a package


=== Zope3/src/zope/modulealias/meta.zcml 1.1 => 1.2 ===
--- /dev/null	Wed Jan 14 17:56:01 2004
+++ Zope3/src/zope/modulealias/meta.zcml	Wed Jan 14 17:55:31 2004
@@ -0,0 +1,11 @@
+<configure 
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directive 
+      namespace="http://namespaces.zope.org/zope"
+      name="modulealias"
+      schema=".metadirectives.IModuleAliasDirective"
+      handler=".metaconfigure.define_module_alias" />
+
+</configure>


=== Zope3/src/zope/modulealias/metaconfigure.py 1.1 => 1.2 ===
--- /dev/null	Wed Jan 14 17:56:02 2004
+++ Zope3/src/zope/modulealias/metaconfigure.py	Wed Jan 14 17:55:31 2004
@@ -0,0 +1,49 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+modulealiases package allows you to make module alias declarations via zcml,
+e.g.:
+
+<modulealias module="some.existing.package" alias="some.nonexistent.package" />
+$Id$
+"""
+
+import sys
+import types
+
+class ModuleAliasException(Exception):
+    pass
+
+def define_module_alias(_context, module, alias):
+    _context.action(
+        discriminator = None,
+        callable = alias_module,
+        args = (module, alias, _context),
+        )
+
+def alias_module(module, alias, context):
+    """ define a module alias by munging sys.modules """
+    module_ob = context.resolve(module)
+    alias_ob = sys.modules.get(alias)
+    if not isinstance(module_ob, types.ModuleType):
+        raise ModuleAliasException(
+            '"module" %s does not resolve to a module' % module)
+
+    if alias_ob is not None and alias_ob is not module_ob: 
+        raise ModuleAliasException(
+            '"alias" module %s already exists in sys.modules' % alias)
+    
+    sys.modules[alias] = module_ob
+


=== Zope3/src/zope/modulealias/metadirectives.py 1.1 => 1.2 ===
--- /dev/null	Wed Jan 14 17:56:02 2004
+++ Zope3/src/zope/modulealias/metadirectives.py	Wed Jan 14 17:55:31 2004
@@ -0,0 +1,21 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+from zope.configuration.fields import PythonIdentifier
+from zope.interface import Interface
+
+class IModuleAliasDirective(Interface):
+    """ Define a new module alias """
+    module = PythonIdentifier()
+    alias = PythonIdentifier()




More information about the Zope3-Checkins mailing list