diff options
author | Jason Madden <jason+github@nextthought.com> | 2018-09-26 14:35:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-26 14:35:43 -0500 |
commit | ec6f51d2fa8beba3705a083fadece3c9c66ee48e (patch) | |
tree | 3c1d461ca0bfe5e0d5bfbcbd9cdeb7a6f70ba12d | |
parent | abac0539cfae8365ca69b949983f588ec9bbfe52 (diff) | |
parent | beff5919177a1ff76e7343aeef6dc0c7b2417c64 (diff) | |
download | zope-configuration-ec6f51d2fa8beba3705a083fadece3c9c66ee48e.tar.gz |
Merge pull request #37 from zopefoundation/issue35
Fix GlobalObject breaking with just a .
-rw-r--r-- | CHANGES.rst | 4 | ||||
-rw-r--r-- | src/zope/configuration/fields.py | 13 | ||||
-rw-r--r-- | src/zope/configuration/tests/test_fields.py | 16 |
3 files changed, 28 insertions, 5 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 57d0c26..603460c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,9 @@ Changes 4.2.1 (unreleased) ------------------ -- Nothing changed yet. +- Fix ``GlobalObject`` (and ``GlobalInterface``) no longer allowing + just a single '.'. See `issue 35 + <https://github.com/zopefoundation/zope.configuration/issues/35>`_. 4.2.0 (2018-09-26) diff --git a/src/zope/configuration/fields.py b/src/zope/configuration/fields.py index e934f69..70527a5 100644 --- a/src/zope/configuration/fields.py +++ b/src/zope/configuration/fields.py @@ -35,7 +35,11 @@ from zope.configuration.interfaces import InvalidToken class PythonIdentifier(schema_PythonIdentifier): """ - This class is like `zope.schema.PythonIdentifier`, but does not allow empty strings. + This class is like `zope.schema.PythonIdentifier`. + + .. versionchanged:: 4.2.0 + Extend `zope.schema.PythonIdentifier`, which implies that `fromUnicode` + validates the strings. """ def _validate(self, value): @@ -73,9 +77,12 @@ class GlobalObject(Field): try: # Leading dots are allowed here to indicate current - # package. + # package, but not accepted by DottedName. Take care, + # though, because a single dot is valid to resolve, but + # not valid to pass to DottedName (as an empty string) to_validate = name[1:] if name.startswith('.') else name - self._DOT_VALIDATOR.validate(to_validate) + if to_validate: + self._DOT_VALIDATOR.validate(to_validate) except ValidationError as v: v.with_field_and_value(self, name) raise diff --git a/src/zope/configuration/tests/test_fields.py b/src/zope/configuration/tests/test_fields.py index 734572e..6964957 100644 --- a/src/zope/configuration/tests/test_fields.py +++ b/src/zope/configuration/tests/test_fields.py @@ -92,9 +92,23 @@ class GlobalObjectTests(unittest.TestCase, _ConformsToIFromUnicode): context = Context() bound = go.bind(context) found = bound.fromUnicode('tried') - self.assertTrue(found is _target) + self.assertIs(found, _target) self.assertEqual(context._resolved, 'tried') + def test_fromUnicode_w_resolve_dot(self): + _target = object() + class Context(object): + _resolved = None + def resolve(self, name): + self._resolved = name + return _target + go = self._makeOne() + context = Context() + bound = go.bind(context) + found = bound.fromUnicode('.') + self.assertIs(found, _target) + self.assertEqual(context._resolved, '.') + def test_fromUnicode_w_resolve_but_validation_fails(self): from zope.schema import Text from zope.schema import ValidationError |