From 6cc96689989a7781f1da4ae05b0fbc38e6c8fdb9 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 29 Jun 2009 03:16:10 +0000 Subject: Add changelog entry for resource directive. Rejigger error detection ordering. --- repoze/bfg/tests/test_zcml.py | 6 ++++-- repoze/bfg/zcml.py | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'repoze') diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py index 875628f5f..a8eec3d48 100644 --- a/repoze/bfg/tests/test_zcml.py +++ b/repoze/bfg/tests/test_zcml.py @@ -864,12 +864,14 @@ class TestResourceDirective(unittest.TestCase): def test_override_directory_with_file(self): from zope.configuration.exceptions import ConfigurationError context = DummyContext() - self.assertRaises(ConfigurationError, self._callFUT, context, 'a/', 'a') + self.assertRaises(ConfigurationError, self._callFUT, context, + 'a:foo/', 'a:foo.pt') def test_override_file_with_directory(self): from zope.configuration.exceptions import ConfigurationError context = DummyContext() - self.assertRaises(ConfigurationError, self._callFUT, context, 'a', 'a/') + self.assertRaises(ConfigurationError, self._callFUT, context, + 'a:foo.pt', 'a:foo/') def test_no_colons(self): from repoze.bfg.zcml import _override diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py index 38db4ead7..14b843bb1 100644 --- a/repoze/bfg/zcml.py +++ b/repoze/bfg/zcml.py @@ -192,18 +192,6 @@ def resource(context, to_override, override_with): if to_override == override_with: raise ConfigurationError('You cannot override a resource with itself') - if to_override.endswith('/'): - if not override_with.endswith('/'): - raise ConfigurationError( - 'A directory cannot be overridden with a file (put a slash ' - 'at the end of override_with if necessary)') - - if override_with.endswith('/'): - if not to_override.endswith('/'): - raise ConfigurationError( - 'A file cannot be overridden with a directory (put a slash ' - 'at the end of to_override if necessary)') - package = to_override path = '' if ':' in to_override: @@ -214,6 +202,18 @@ def resource(context, to_override, override_with): if ':' in override_with: override_package, override_prefix = override_with.split(':', 1) + if path.endswith('/'): + if not override_prefix.endswith('/'): + raise ConfigurationError( + 'A directory cannot be overridden with a file (put a slash ' + 'at the end of override_with if necessary)') + + if override_prefix.endswith('/'): + if not path.endswith('/'): + raise ConfigurationError( + 'A file cannot be overridden with a directory (put a slash ' + 'at the end of to_override if necessary)') + package = context.resolve(package).__name__ override_package = context.resolve(package).__name__ -- cgit v1.2.3