From 46c2c31715da4b753e54e8ea9661ab32dcbb9980 Mon Sep 17 00:00:00 2001 From: Steffen Allner Date: Fri, 15 May 2020 13:39:25 +0200 Subject: [PATCH] Adapt to changes in `zope.configuration 4.4`. The refactoring of exception nesting there breaks the wrongly imported ConfigurationError here. --- CHANGES.rst | 2 ++ setup.py | 2 +- src/zope/app/form/browser/form.rst | 10 +++++----- src/zope/app/form/browser/metaconfigure.py | 8 +++++--- src/zope/app/form/browser/tests/test_form.py | 5 ++--- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index fb79fd1..6441372 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,8 @@ CHANGES - Drop support for Python 3.4. +- Adapt to changes in ``zope.configuration >= 4.4``. + 5.1.0 (2018-10-22) ================== diff --git a/setup.py b/setup.py index 58e807c..a9856f8 100644 --- a/setup.py +++ b/setup.py @@ -87,7 +87,7 @@ def read(*rnames): "zope.browserpage >= 3.10.1", "zope.browsermenu", "zope.component", - "zope.configuration >= 4.1.0", + "zope.configuration >= 4.4.0", "zope.datetime", "zope.exceptions", "zope.i18n", diff --git a/src/zope/app/form/browser/form.rst b/src/zope/app/form/browser/form.rst index a41b39d..2acea58 100644 --- a/src/zope/app/form/browser/form.rst +++ b/src/zope/app/form/browser/form.rst @@ -177,8 +177,7 @@ Now, if I do not specify my own template, and my class does not overwrite the >>> sys.modules['form'].NewDataHandler = NewDataHandler - >>> try: - ... xmlconfig.string(''' + >>> xmlconfig.string(''' ... @@ -194,10 +193,11 @@ Now, if I do not specify my own template, and my class does not overwrite the ... ... ... ''', context) - ... except xmlconfig.ConfigurationError as e: - ... print(e) - You must specify a class that implements `getData()` and `setData()`, if you do not overwrite `update()`. + Traceback (most recent call last): + ... + ZopeXMLConfigurationError: You must specify a class that implements `getData()` and `setData()`, if you do not overwrite `update()`. File "", line 6.6 + zope.configuration.exceptions.ConfigurationError Now we need to clean up afterwards. diff --git a/src/zope/app/form/browser/metaconfigure.py b/src/zope/app/form/browser/metaconfigure.py index 892160b..09d5170 100644 --- a/src/zope/app/form/browser/metaconfigure.py +++ b/src/zope/app/form/browser/metaconfigure.py @@ -23,6 +23,7 @@ from zope.security.checker import CheckerPublic from zope.interface import implementedBy from zope.configuration.exceptions import ConfigurationError +from zope.configuration.xmlconfig import ZopeXMLConfigurationError from zope.browser.interfaces import IAdding from zope.schema import getFieldNamesInOrder @@ -113,7 +114,7 @@ def _normalize(self): if self.template is not None: self.template = os.path.abspath(str(self.template)) if not os.path.isfile(self.template): - raise ConfigurationError("No such file", self.template) + raise ZopeXMLConfigurationError("No such file", self.template) else: self.template = self.default_template @@ -286,9 +287,10 @@ def __init__(self, _context, **kwargs): attrs = self.class_.__dict__.keys() if 'template' not in kwargs.keys() and 'update' not in attrs and \ ('getData' not in attrs or 'setData' not in attrs): - raise ConfigurationError( + raise ZopeXMLConfigurationError( "You must specify a class that implements `getData()` " - "and `setData()`, if you do not overwrite `update()`.") + "and `setData()`, if you do not overwrite `update()`.", + ConfigurationError()) class SubeditFormDirective(EditFormDirectiveBase): diff --git a/src/zope/app/form/browser/tests/test_form.py b/src/zope/app/form/browser/tests/test_form.py index 34418c8..6b68acc 100644 --- a/src/zope/app/form/browser/tests/test_form.py +++ b/src/zope/app/form/browser/tests/test_form.py @@ -33,8 +33,6 @@ checker = renormalizing.RENormalizing([ (re.compile("u('.*?')"), r"\1"), (re.compile('u(".*?")'), r"\1"), - # Python 3 adds module name to exceptions. - (re.compile('zope.configuration.xmlconfig.ZopeXMLConfigurationError'), 'ZopeXMLConfigurationError'), ]) @@ -47,7 +45,8 @@ def test_suite(): return unittest.TestSuite(( doctest.DocFileSuite('../form.rst', setUp=setUp, tearDown=testing.tearDown, - optionflags=doctest.NORMALIZE_WHITESPACE), + optionflags=doctest.NORMALIZE_WHITESPACE + | doctest.IGNORE_EXCEPTION_DETAIL), )) if __name__ == '__main__':