[Zope3-checkins] SVN: Zope3/trunk/src/zope/configuration/ Remove backward-compatiblity code to old style ZCML.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Jul 13 19:23:18 EDT 2004


Log message for revision 26513:
  Remove backward-compatiblity code to old style ZCML.
  


Changed:
  D   Zope3/trunk/src/zope/configuration/backward.py
  U   Zope3/trunk/src/zope/configuration/config.py
  D   Zope3/trunk/src/zope/configuration/tests/backward.zcml
  D   Zope3/trunk/src/zope/configuration/tests/backwardkw.zcml
  D   Zope3/trunk/src/zope/configuration/tests/backwardkwextra.zcml
  D   Zope3/trunk/src/zope/configuration/tests/test_backward.py


-=-
Deleted: Zope3/trunk/src/zope/configuration/backward.py
===================================================================
--- Zope3/trunk/src/zope/configuration/backward.py	2004-07-13 22:27:31 UTC (rev 26512)
+++ Zope3/trunk/src/zope/configuration/backward.py	2004-07-13 23:23:17 UTC (rev 26513)
@@ -1,418 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Pre-zcml-geddon backward compatability
-
-Rather than revisit all of the old meta configurations, we'll
-support the old configurations for a time until they can be converted.
-There are two aspects of this:
-
-1. Supporting complex directives (as opposed to simple and grouping
-   directives). This support is actually provided in config.py.
-   We'll probably support complex directives indefinately, as there
-   are some pretty complicated handlers in place now that we don't
-   want to take time to rewrite any time soon.
-
-2. Supporting the old-style meta-configuration ZCML directives:
-   zope:directives, zope:directive, zope:description, and
-   zope:attribute.  Hopefully, we can get rid of these sooner by
-   converting the existing meta configurations to use the new
-   meta: directives and schema. Certainly directives with message ids
-   will need to be converted.
-
-This file contains the implementations of the old-style meta
-configurations.
-
-$Id$
-"""
-
-from keyword import iskeyword
-from zope.configuration import config
-from zope import interface
-from zope import schema
-
-
-class IDescribed(interface.Interface):
-
-    name = schema.TextLine(
-        title=u"Directive name",
-        description=u"The name of the directive being defined"
-        )
-
-    description = schema.Text(
-        title=u"Directive discription",
-        description=u"This should document how the directive is used.",
-        default=u"",
-        )
-
-class ISubdirectiveInfo(IDescribed):
-    """Information common to all directive definitions have
-    """
-
-    attributes = schema.Bytes(
-        title=u"Attribute names",
-        description=u"This is a space-speratated list of attribute names. "
-                    u"This is used to provide a mimimal specification the "
-                    u"attributes used.",
-        default="",
-        )
-
-class IDirectiveInfo(ISubdirectiveInfo):
-    """Information common to all directive definitions have
-    """
-    
-    handler = config.fields.GlobalObject(
-        title=u"Directive handler",
-        description=u"The dotted name of the directive handler",
-        )
-
-class ISubdirectiveContext(ISubdirectiveInfo, config.IConfigurationContext):
-    pass
-
-class IDirectiveContext(IDirectiveInfo, ISubdirectiveContext):
-    pass
-
-
-class Described:
-
-    interface.implements(IDescribed)
-
-    description = u''
-            
-    def _merge_description_and_info(self):
-        r"""Combind a description, given as an attribute with info text
-
-        >>> d = Described()
-        >>> d.info = Described() # Any object with attributes will do
-        >>> d.info.text = u''
-        >>> d._merge_description_and_info()
-        >>> d.info.text
-        u''
-
-        >>> d.info.text = u'   \n  '
-        >>> d._merge_description_and_info()
-        >>> d.info.text
-        u'   \n  '
-
-        >>> d.description = u'test directive'
-        >>> d._merge_description_and_info()
-        >>> d.info.text
-        u'test directive'
-
-        >>> d.info.text = u'blah\nblah'
-        >>> d._merge_description_and_info()
-        >>> d.info.text
-        u'test directive\n\nblah\nblah'
-        
-        """
-        if self.description:
-            if self.info.text.strip():
-                self.info.text = self.description + u"\n\n" + self.info.text
-            else:
-                self.info.text = self.description
-
-class Attributed(config.GroupingContextDecorator):
-    """Compute schema definitions from simple attribute specifications
-
-    The attribute specifications can be given as simple names in the
-    constructor:
-
-    >>> context = config.ConfigurationMachine()
-    >>> x = Attributed(context, attributes=u"a b c")
-
-    Or the can be provides as keys added to the attributes disctionary:
-
-    >>> x.attributes['foo'] = schema.Int(title=u"Foo")
-
-    When tha _schema_from_attrs method is called, a schema is computed:
-
-    >>> x._schema_from_attrs()
-    >>> for name in x.schema:
-    ...   f = x.schema[name]
-    ...   print f.__class__.__name__, f.__name__, f.title, int(f.required)
-    Text a a 0
-    Text c c 0
-    Text b b 0
-    Int foo Foo 1
-
-    If you need to be able to accept arbritrary parameters, include an
-    attribute named "*" in the list of attributes:
-
-    >>> context = config.ConfigurationMachine()
-    >>> x = Attributed(context, attributes=u"a b c *")
-    >>> x._schema_from_attrs()
-    >>> for name in x.schema:
-    ...   f = x.schema[name]
-    ...   print f.__class__.__name__, f.__name__, f.title, int(f.required)
-    Text a a 0
-    Text c c 0
-    Text b b 0
-
-    Note that we don't see "*" in the schema. Rather, we see that the
-    schema as a tagged value:
-
-    >>> x.schema.getTaggedValue("keyword_arguments")
-    1
-
-    Indicating that the directive handler accepts extra keyword
-    arguments, which means that arbitrary extra parameters can be given.
-    """
-
-    interface.implementsOnly(IDescribed)
-
-    __keyword_arguments = False
-
-    def attribute(self, name, required=False, description=u''):
-        if name == '*':
-            self.__keyword_arguments = True
-            return
-        
-        aname = str(name)
-        if iskeyword(name):
-            aname += '_'
-        self.attributes[aname] = schema.Text(
-            title = unicode(aname),
-            required = required,
-            description = description,
-            )
-
-    def __init__(self, context, attributes=u'', **kw):
-        config.GroupingContextDecorator.__init__(self, context, **kw)
-        self.attributes = {}
-        for name in attributes.strip().split():
-            self.attribute(name)
-
-    def _schema_from_attrs(self):
-        schema = interface.Interface.__class__(
-            "schema generated from attributes",
-            (interface.Interface, ),
-            self.attributes,
-            )
-        if not self.attributes:
-            # No attribute definitions, allow keyword args
-            schema.setTaggedValue('keyword_arguments', True)
-        self.schema = schema
-
-        if self.__keyword_arguments:
-            schema.setTaggedValue('keyword_arguments', True)
-    
-
-class Directive(Attributed, Described):
-    """Handler for the directive directive
-
-    Actual definition of the directive is delayed until
-    sub(meta)directives have been handled.
-
-    See the test in tests/test_backward
-    """
-    interface.implements(IDirectiveContext)
-    usedIn = config.IConfigurationContext
-
-    def __init__(self, context, **kw):
-        Attributed.__init__(self, context, **kw)
-        self.subdirectives = {}
-
-    def after(self):
-        self._schema_from_attrs()
-        self._merge_description_and_info()
-        if self.subdirectives:
-            # we have subdirectives, so set up a complex directive
-            complex = config.ComplexDirectiveDefinition(self)
-            complex.handler = self.handler
-            complex.update(self.subdirectives)
-            complex.before()
-        else:
-            config.defineSimpleDirective(self, self.name, self.schema,
-                                         self.handler, self.namespace)
-
-
-class Subdirective(Attributed, Described):
-    """Handler for the directive directive
-
-    Actual definition of the directive is delayed until
-    sub(meta)directives have been handled.
-
-    >>> context = config.ConfigurationMachine()
-    >>> d = Directive(context)
-    >>> len(d.subdirectives)
-    0
-    >>> s = Subdirective(d, name="foo", attributes=u"a b")
-    >>> len(d.subdirectives)
-    0
-    >>> class Info:
-    ...    text=u'spam'
-    >>> s.info = Info()
-    >>> s.after()
-    >>> len(d.subdirectives)
-    1
-    >>> schema, info = d.subdirectives['foo']
-
-    >>> def sorted(x):
-    ...     r = list(x)
-    ...     r.sort()
-    ...     return r
-
-    >>> sorted(schema)
-    ['a', 'b']
-    >>> info.text
-    u'spam'
-
-    """
-
-    interface.implements(ISubdirectiveContext)
-
-    def after(self):
-        self._schema_from_attrs()
-        self._merge_description_and_info()
-        self.context.subdirectives[self.name] = self.schema, self.info
-
-class IAttribute(IDescribed):
-
-    required = config.fields.Bool(
-        title=u"Required",
-        description=u"Is the attribute required?",
-        required=True,
-        default=False,
-        )
-
-class Attribute(config.GroupingContextDecorator, Described):
-    r"""Simple attribute specification
-
-    Provide a very simple specification of an attribute and add it to
-    the attributes dictionary of the containing context.
-
-    >>> context = config.ConfigurationMachine()
-    >>> d = Directive(context, attributes=u"a")
-    >>> len(d.attributes)
-    1
-
-    >>> a = Attribute(d, name="a", description=u"blah")
-    >>> class Info:
-    ...    text=u'spam'
-    >>> a.info = Info()
-    >>> d.attributes['a'].description
-    u''
-    >>> a.after()
-    >>> d.attributes['a'].description
-    u'blah\n\nspam'
-    >>> d.attributes['a'].required
-    0
-    >>> d.attributes['a'].__class__.__name__
-    'Text'
-
-    >>> a = Attribute(d, name="b", description=u"eek", required=True)
-    >>> class Info:
-    ...    text=u'spam'
-    >>> a.info = Info()
-    >>> a.after()
-    >>> d.attributes['b'].description
-    u'eek\n\nspam'
-    >>> d.attributes['b'].required
-    1
-
-    >>> len(d.attributes)
-    2
-    
-    """
-
-    required = False
-
-    def after(self):
-        self._merge_description_and_info()
-        self.context.attribute(self.name, self.required, self.info.text)
-
-class Description(config.GroupingContextDecorator):
-    r"""Provide descriptions for surrounding directives
-
-    This works a bit hard to be an effective noop, since
-    it has the same effect as providing text data.
-
-    >>> context = config.ConfigurationMachine()
-    >>> d = Directive(context, attributes=u"a")
-    >>> class Info:
-    ...    text=u'spam         \n'
-    >>> d.info = Info()
-
-    >>> des = Description(d)
-    >>> des.info = Info()
-    >>> des.info.text = u"blah\nblah"
-    >>> des.after()
-
-    >>> d.info.text
-    u'spam\n\nblah\nblah'
-    
-    """
-    
-    def after(self):
-        """Merge our info with containing directive's info
-        """
-
-        if not self.info.text.strip():
-            return
-
-        context = self.context
-        old = context.info.text.rstrip()
-        
-        if old:
-            context.info.text = old + u"\n\n" + self.info.text
-        else:
-            context.info.text += self.info.text
-
-
-def bootstrap(context):
-
-    # zope:directives
-    context((config.metans, 'groupingDirective'),
-            name='directives',
-            namespace=config.zopens,
-            handler="zope.configuration.config.DirectivesHandler",
-            schema="zope.configuration.config.IDirectivesInfo"
-            )
-
-    # zope:directive
-    context((config.metans, 'groupingDirective'),
-            name='directive',
-            namespace=config.zopens,
-            usedIn="zope.configuration.config.IDirectivesContext",
-            handler="zope.configuration.backward.Directive",
-            schema="zope.configuration.backward.IDirectiveInfo"
-            )
-
-    # zope:subdirective
-    context((config.metans, 'groupingDirective'),
-            name='subdirective',
-            namespace=config.zopens,
-            usedIn="zope.configuration.backward.IDirectiveContext",
-            handler="zope.configuration.backward.Subdirective",
-            schema="zope.configuration.backward.ISubdirectiveInfo"
-            )
-
-    # zope:attribute
-    context((config.metans, 'groupingDirective'),
-            name='attribute',
-            namespace=config.zopens,
-            usedIn="zope.configuration.backward.ISubdirectiveContext",
-            handler="zope.configuration.backward.Attribute",
-            schema="zope.configuration.backward.IAttribute"
-            )
-
-    # zope:discription
-    context((config.metans, 'groupingDirective'),
-            name='description',
-            namespace=config.zopens,
-            usedIn="zope.configuration.backward.IDescribed",
-            handler="zope.configuration.backward.Description",
-            schema="zope.interface.Interface"
-            )
-
-    

Modified: Zope3/trunk/src/zope/configuration/config.py
===================================================================
--- Zope3/trunk/src/zope/configuration/config.py	2004-07-13 22:27:31 UTC (rev 26512)
+++ Zope3/trunk/src/zope/configuration/config.py	2004-07-13 23:23:17 UTC (rev 26513)
@@ -1568,6 +1568,3 @@
             handler="zope.configuration.config.subdirective",
             schema="zope.configuration.config.IDirectiveInfo"
             )
-
-    import zope.configuration.backward
-    zope.configuration.backward.bootstrap(context)

Deleted: Zope3/trunk/src/zope/configuration/tests/backward.zcml
===================================================================
--- Zope3/trunk/src/zope/configuration/tests/backward.zcml	2004-07-13 22:27:31 UTC (rev 26512)
+++ Zope3/trunk/src/zope/configuration/tests/backward.zcml	2004-07-13 23:23:17 UTC (rev 26513)
@@ -1,56 +0,0 @@
-<configure 
-  xmlns="http://namespaces.zope.org/zope"
-  xmlns:test="http://namespaces.zope.org/test"
-  package="zope.configuration.tests.directives"
-  >
-
-  <directives namespace="http://namespaces.zope.org/test">
-  
-     <directive name="simple" attributes="a b c"
-                handler=".simple" description="simple example" />
-          
-  
-     <directive name="newsimple" handler=".newsimple">
-
-        <attribute name="a" description="a descr" required="yes" />
-        <attribute name="b">
-            <description>b descr</description>
-        </attribute>
-        <attribute name="c" required="yes" >
-            c descr
-        </attribute>
-
-     </directive>
-  </directives>
-
-  <test:simple a="aa" c="cc">first</test:simple>
-  <test:newsimple a="naa" c="ncc" b="nbb">second</test:newsimple>
-
-  <directives namespace="http://namespaces.zope.org/test">
-
-     <directive name="testc" handler=".Complex">
-
-        <attribute name="a" description="a descr" required="yes" />
-        <attribute name="b">
-            <description>b descr</description>
-        </attribute>
-        <attribute name="c" required="yes">
-            c descr
-        </attribute>
-
-        <subdirective name="factory">
-          <attribute name="factory" required="yes" />
-        </subdirective>
-     </directive>
-
-  </directives>
-    
-  <test:testc a="ca" c="cc">
-     Third
-     <test:factory factory=".f">
-        Fourth
-     </test:factory>    
-  </test:testc>
-
-</configure>
-

Deleted: Zope3/trunk/src/zope/configuration/tests/backwardkw.zcml
===================================================================
--- Zope3/trunk/src/zope/configuration/tests/backwardkw.zcml	2004-07-13 22:27:31 UTC (rev 26512)
+++ Zope3/trunk/src/zope/configuration/tests/backwardkw.zcml	2004-07-13 23:23:17 UTC (rev 26513)
@@ -1,30 +0,0 @@
-<configure 
-  xmlns="http://namespaces.zope.org/zope"
-  xmlns:test="http://namespaces.zope.org/test"
-  package="zope.configuration.tests.directives"
-  >
-
-  <directives namespace="http://namespaces.zope.org/test">
-  
-     <directive name="k" attributes="for class x"
-                handler=".k" description="simple example w python keywords" />
-          
-  
-     <directive name="k2" handler=".k">
-
-        <attribute name="for" description="for descr" required="yes" />
-        <attribute name="class">
-            <description>class descr</description>
-        </attribute>
-        <attribute name="x" required="yes" >
-            x descr
-        </attribute>
-
-     </directive>
-  </directives>
-
-  <test:k  for="f"  class="c"  x="x" >first</test:k>
-  <test:k2 for="ff" class="cc" x="xx">second</test:k2>
-
-</configure>
-

Deleted: Zope3/trunk/src/zope/configuration/tests/backwardkwextra.zcml
===================================================================
--- Zope3/trunk/src/zope/configuration/tests/backwardkwextra.zcml	2004-07-13 22:27:31 UTC (rev 26512)
+++ Zope3/trunk/src/zope/configuration/tests/backwardkwextra.zcml	2004-07-13 23:23:17 UTC (rev 26513)
@@ -1,17 +0,0 @@
-<configure 
-  xmlns="http://namespaces.zope.org/zope"
-  xmlns:test="http://namespaces.zope.org/test"
-  package="zope.configuration.tests.directives"
-  >
-
-  <directives namespace="http://namespaces.zope.org/test">
-  
-     <directive name="k" attributes="for * class x"
-                handler=".kkw" />
-          
-  </directives>
-
-  <test:k  for="f"  class="c"  x="x" a="a" b="b" />
-
-</configure>
-

Deleted: Zope3/trunk/src/zope/configuration/tests/test_backward.py
===================================================================
--- Zope3/trunk/src/zope/configuration/tests/test_backward.py	2004-07-13 22:27:31 UTC (rev 26512)
+++ Zope3/trunk/src/zope/configuration/tests/test_backward.py	2004-07-13 23:23:17 UTC (rev 26513)
@@ -1,122 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Test backward-compatiblity.
-
-$Id$
-"""
-import unittest
-from zope.testing.doctestunit import DocTestSuite
-from zope.configuration import config, xmlconfig
-from zope.configuration.tests.test_xmlconfig import clean_text_w_paths
-
-def test_directive_and_integration():
-    r"""
-
-    To see if the backward compatability meta configurations are
-    working, well evaluate a test zcml file and see if we get the
-    expected actions:
-
-    >>> from zope.configuration import tests
-    >>> context = xmlconfig.file("backward.zcml", tests, execute=False)
-    >>> for action in context.actions:
-    ...   print action[:2]
-    ...   print action[2]
-    ...   print clean_text_w_paths(unicode(action[5]))
-    ...   if action[5].text.strip():
-    ...      print action[5].text.strip()
-    (('simple', u'aa', u'xxx', u'cc'), f)
-    (u'aa', u'xxx', u'cc')
-    File "tests/backward.zcml", line 26.2-26.34
-        <test:simple a="aa" c="cc">first</test:simple>
-    first
-    (('newsimple', u'naa', u'nbb', u'ncc'), f)
-    (u'naa', u'nbb', u'ncc')
-    File "tests/backward.zcml", line 27.2-27.48
-        <test:newsimple a="naa" c="ncc" b="nbb">second</test:newsimple>
-    second
-    ('Complex.__init__', None)
-    ()
-    File "tests/backward.zcml", line 48.2-53.2
-        <test:testc a="ca" c="cc">
-           Third
-           <test:factory factory=".f">
-              Fourth
-           </test:factory>
-        </test:testc>
-    Third
-    (('Complex.factory', 1, 2), u'.f')
-    (u'ca',)
-    File "tests/backward.zcml", line 50.5-52.5
-           <test:factory factory=".f">
-              Fourth
-           </test:factory>
-    Fourth
-    (('Complex', 1, 2), f)
-    (u'xxx', u'cc')
-    File "tests/backward.zcml", line 48.2-53.2
-        <test:testc a="ca" c="cc">
-           Third
-           <test:factory factory=".f">
-              Fourth
-           </test:factory>
-        </test:testc>
-    Third
-
-    """
-
-def test_directive_and_integration_w_python_keywords():
-    r"""
-
-    >>> from zope.configuration import tests
-    >>> context = xmlconfig.file("backwardkw.zcml", tests, execute=False)
-    >>> for action in context.actions:
-    ...   print action[:2]
-    ...   print action[2]
-    ...   print clean_text_w_paths(unicode(action[5]))
-    ...   print action[5].text.strip()
-    (('k', u'f'), f)
-    (u'f', u'c', u'x')
-    File "tests/backwardkw.zcml", line 26.2-26.43
-        <test:k  for="f"  class="c"  x="x" >first</test:k>
-    first
-    (('k', u'ff'), f)
-    (u'ff', u'cc', u'xx')
-    File "tests/backwardkw.zcml", line 27.2-27.44
-        <test:k2 for="ff" class="cc" x="xx">second</test:k2>
-    second
-    
-    """
-
-def test_directive_and_integration_w_extra_arguments():
-    r"""
-
-    >>> from zope.configuration import tests
-    >>> context = xmlconfig.file("backwardkwextra.zcml", tests, execute=False)
-    >>> for action in context.actions:
-    ...   print action[:2]
-    ...   print action[2]
-    ...   print clean_text_w_paths(unicode(action[5]))
-    (('k', u'f'), f)
-    (u'f', u'c', u'x', {'a': u'a', 'b': u'b'})
-    File "tests/backwardkwextra.zcml", line 14.2-14.51
-        <test:k  for="f"  class="c"  x="x" a="a" b="b" />
-    """
-
-def test_suite():
-    return unittest.TestSuite((
-        DocTestSuite('zope.configuration.backward'),
-        DocTestSuite(),
-        ))
-
-if __name__ == '__main__': unittest.main()



More information about the Zope3-Checkins mailing list