[Checkins] SVN: z3c.unconfigure/trunk/ Initial import.

Philipp von Weitershausen philikon at philikon.de
Wed Aug 6 04:20:32 EDT 2008


Log message for revision 89424:
  Initial import.
  
  This is a package that allows you to disable specific bits of ZCML that
  may occur in other packages by saying
  
    <unconfigure>
      ... directives here that you would like to be undone
    </unconfigure>
  
  

Changed:
  A   z3c.unconfigure/trunk/
  A   z3c.unconfigure/trunk/CHANGES.txt
  A   z3c.unconfigure/trunk/README.txt
  A   z3c.unconfigure/trunk/buildout.cfg
  A   z3c.unconfigure/trunk/setup.py
  A   z3c.unconfigure/trunk/src/
  A   z3c.unconfigure/trunk/src/z3c/
  A   z3c.unconfigure/trunk/src/z3c/__init__.py
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/README.txt
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/__init__.py
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/config.py
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/testing.py
  A   z3c.unconfigure/trunk/src/z3c/unconfigure/tests.py

-=-
Added: z3c.unconfigure/trunk/CHANGES.txt
===================================================================
--- z3c.unconfigure/trunk/CHANGES.txt	                        (rev 0)
+++ z3c.unconfigure/trunk/CHANGES.txt	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1,7 @@
+Changes
+=======
+
+1.0 (unreleased)
+----------------
+
+First public release.


Property changes on: z3c.unconfigure/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.unconfigure/trunk/README.txt
===================================================================
--- z3c.unconfigure/trunk/README.txt	                        (rev 0)
+++ z3c.unconfigure/trunk/README.txt	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1 @@
+Please refer to src/z3c/unconfigure/README.txt


Property changes on: z3c.unconfigure/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.unconfigure/trunk/buildout.cfg
===================================================================
--- z3c.unconfigure/trunk/buildout.cfg	                        (rev 0)
+++ z3c.unconfigure/trunk/buildout.cfg	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1,13 @@
+[buildout]
+develop = .
+parts = interpreter test
+
+[interpreter]
+recipe = zc.recipe.egg
+eggs = z3c.unconfigure
+interpreter = python
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.unconfigure
+defaults = ['-v']

Added: z3c.unconfigure/trunk/setup.py
===================================================================
--- z3c.unconfigure/trunk/setup.py	                        (rev 0)
+++ z3c.unconfigure/trunk/setup.py	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1,38 @@
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+long_description = (
+    read('src', 'z3c', 'unconfigure', 'README.txt')
+    + '\n' +
+    read('CHANGES.txt')
+    )
+
+setup(
+    name='z3c.unconfigure',
+    version='1.0dev',
+    description=("Disable specific ZCML directives in other package's "
+                 "configuration"),
+    long_description=long_description,
+    author='Philipp von Weitershausen',
+    author_email='philipp at weitershausen.de',
+    url='http://pypi.python.org/pypi/z3c.unconfigure',
+    license='ZPL',
+    classifiers=["Programming Language :: Python",
+                 'Intended Audience :: Developers',
+                 'License :: OSI Approved :: Zope Public License',
+                 'Programming Language :: Python',
+                 ],
+
+    packages=find_packages('src'),
+    package_dir={'': 'src'},
+    namespace_packages=['z3c'],
+    include_package_data=True,
+    zip_safe=False,
+    install_requires=['setuptools',
+                      'zope.configuration',
+                      'zope.testing',
+                      ],
+    )


Property changes on: z3c.unconfigure/trunk/setup.py
___________________________________________________________________
Name: svn:eol-style
   + native


Property changes on: z3c.unconfigure/trunk/src
___________________________________________________________________
Name: svn:ignore
   + *.egg-info


Added: z3c.unconfigure/trunk/src/z3c/__init__.py
===================================================================
--- z3c.unconfigure/trunk/src/z3c/__init__.py	                        (rev 0)
+++ z3c.unconfigure/trunk/src/z3c/__init__.py	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)


Property changes on: z3c.unconfigure/trunk/src/z3c/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.unconfigure/trunk/src/z3c/unconfigure/README.txt
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/README.txt	                        (rev 0)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/README.txt	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1,41 @@
+This package allows you to disable specific bits of ZCML configuration
+that may occur in other packages.  For instance, let's consider a
+simple ZCML directive that prints strings:
+
+  >>> zcml("""
+  ... <print msg="Hello World!" />
+  ... """)
+  Hello World!
+
+Now let's say this directive were used a bunch of times, but we wanted
+to prevent one or two of its occurrences.  To do that we simply repeat
+the directive inside the ``unconfigure`` grouping directive.  This
+grouping directive will look at all the previous directives and filter
+out the ones we want to exclude:
+
+  >>> zcml("""
+  ... <configure>
+  ...   <print msg="Hello World!" />
+  ...   <print msg="I can has cheezburger?" />
+  ...   <print msg="Goodbye World!" />
+  ...   <print msg="LOL!" />
+  ...
+  ...   <unconfigure>
+  ...     <print msg="I can has cheezburger?" />
+  ...     <print msg="LOL!" />
+  ...   </unconfigure>
+  ... </configure>
+  ... """)
+  Hello World!
+  Goodbye World!
+
+If you're trying to unconfigure something that hasn't been configured
+in the first place, nothing will happen:
+
+  >>> zcml("""
+  ... <configure>
+  ...   <unconfigure>
+  ...     <print msg="I can has cheezburger?" />
+  ...   </unconfigure>
+  ... </configure>
+  ... """)


Property changes on: z3c.unconfigure/trunk/src/z3c/unconfigure/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.unconfigure/trunk/src/z3c/unconfigure/__init__.py
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/__init__.py	                        (rev 0)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/__init__.py	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1 @@
+# Make this package a directory


Property changes on: z3c.unconfigure/trunk/src/z3c/unconfigure/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.unconfigure/trunk/src/z3c/unconfigure/config.py
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/config.py	                        (rev 0)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/config.py	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1,37 @@
+from zope.configuration.zopeconfigure import ZopeConfigure
+
+class Unconfigure(ZopeConfigure):
+
+    def __init__(self, context, **kw):
+        super(Unconfigure, self).__init__(context, **kw)
+        # Make a new actions list here.  This will shadow
+        # context.actions which would otherwise be "inherited" by our
+        # superclass's __getattr__.  By shadowing the original list,
+        # all actions within 'unconfigure' will be added to this list
+        # here, not the global actions list. 
+        self.actions = []
+
+    def after(self):
+        # Get a discriminator -> action representation of all the
+        # actions that have been churned out so far.
+        unique = dict((action[0], action) for action in self.context.actions)
+
+        # Now let's go through the actions within 'unconfigure'
+        # (hereafter called "unactions" :)) and use their
+        # discriminator to remove the real actions
+        for unaction in self.actions:
+            discriminator = unaction[0]
+            if discriminator is None:
+                # XXX apply special majyck for subscribers here
+                continue
+            action = unique.get(discriminator)
+            if action is None:
+                # Trying to unconfigure something that hasn't been
+                # configured in the first place.  Ignore.
+                continue
+
+            # An action by the same discriminator has been found,
+            # let's remove it from the configuration machine's actions
+            # list.
+            self.context.actions.remove(action)
+            del unique[discriminator]


Property changes on: z3c.unconfigure/trunk/src/z3c/unconfigure/config.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.unconfigure/trunk/src/z3c/unconfigure/testing.py
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/testing.py	                        (rev 0)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/testing.py	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1,15 @@
+from zope.interface import Interface
+from zope.schema import Text
+
+class IPrint(Interface):
+    msg = Text(title=u'Message')
+
+def print_(_context, msg):
+    _context.action(
+        discriminator=('print', msg),
+        callable=do_print,
+        args=(msg,),
+        )
+
+def do_print(msg):
+    print msg


Property changes on: z3c.unconfigure/trunk/src/z3c/unconfigure/testing.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.unconfigure/trunk/src/z3c/unconfigure/tests.py
===================================================================
--- z3c.unconfigure/trunk/src/z3c/unconfigure/tests.py	                        (rev 0)
+++ z3c.unconfigure/trunk/src/z3c/unconfigure/tests.py	2008-08-06 08:20:32 UTC (rev 89424)
@@ -0,0 +1,30 @@
+import zope.testing.cleanup
+from zope.testing import doctest
+from zope.configuration import config
+from zope.configuration import xmlconfig
+from zope.configuration import zopeconfigure
+from z3c.unconfigure.config import Unconfigure
+from z3c.unconfigure import testing
+
+def tearDown(test):
+    zope.testing.cleanup.cleanUp()
+
+def zcml(source):
+    context = config.ConfigurationMachine()
+    xmlconfig.registerCommonDirectives(context)
+    config.defineGroupingDirective(context,
+                                   name='unconfigure',
+                                   namespace="*",
+                                   schema=zopeconfigure.IZopeConfigure,
+                                   handler=Unconfigure)
+    config.defineSimpleDirective(
+        context, "print", testing.IPrint, testing.print_, namespace="*")
+
+    xmlconfig.string(source, context)
+
+
+def test_suite():
+    return doctest.DocFileSuite('README.txt',
+                                package='z3c.unconfigure',
+                                globs={'zcml': zcml},
+                                tearDown=tearDown)


Property changes on: z3c.unconfigure/trunk/src/z3c/unconfigure/tests.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list