Products.validation/no_at: Finalize Python 3 compatibility
Tom Gross <jenkins-z4DKO/[email protected]> Sun, 30 Jul 2017 14:34:19 -0700 (PDT)
| Newsgroups | gmane.comp.web.zope.plone.cvs |
|---|---|
| Message-ID | <[email protected]> |
Repository: Products.validation Branch: refs/heads/no_at Date: 2017-07-30T21:34:05Z Author: Tom Gross (tomgross) <[email protected]> Commit: https://github.com/plone/Products.validation/commit/0f940b872abb43d4e698e2504728d872f09fe73a Finalize Python 3 compatibility Files changed: M CHANGES.txt M Products/validation/service.py M Products/validation/tests/test_validation.py M Products/validation/validators/RegexValidator.py M setup.py diff --git a/CHANGES.txt b/CHANGES.txt index 4b0f3f8..4055927 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,7 +10,8 @@ Breaking changes: New features: -- *add item here* +- Python 3 compatibility + [tomgross] Bug fixes: diff --git a/Products/validation/service.py b/Products/validation/service.py index 2a495d9..898fdd6 100644 --- a/Products/validation/service.py +++ b/Products/validation/service.py @@ -21,7 +21,7 @@ def validate(self, name_or_validator, value, *args, **kwargs): __call__ = validate def validatorFor(self, name_or_validator): - if type(name_or_validator) in six.string_types: + if isinstance(name_or_validator, str): try: return self._validator[name_or_validator] except KeyError: @@ -50,7 +50,7 @@ def values(self): return [v for k, v in self.items()] def unregister(self, name_or_validator): - if type(name_or_validator) == six.binary_type: + if isinstance(name_or_validator, str): name = name_or_validator elif IValidator.implementedBy(name_or_validator): name = name_or_validator.name diff --git a/Products/validation/tests/test_validation.py b/Products/validation/tests/test_validation.py index 335e133..245e924 100644 --- a/Products/validation/tests/test_validation.py +++ b/Products/validation/tests/test_validation.py @@ -24,12 +24,16 @@ def test_isPrintable(self): v = validation.validatorFor('isPrintable') self.assertEqual(v('text'), 1) self.assertEqual( - v('\u203'), + v('\\u203'), u"Validation failed(isPrintable): '\\u203' contains unprintable characters" ) + if six.PY3: + int_type = "<class 'int'>" + else: + int_type = "<type 'int'>" self.assertEqual( v(10), - u"Validation failed(isPrintable): 10 of type <type 'int'>, expected 'string'" + u"Validation failed(isPrintable): 10 of type {0}, expected 'string'".format(int_type) ) def test_isSSN(self): @@ -76,7 +80,7 @@ def test_isMailto(self): def test_isUnixLikeName(self): v = validation.validatorFor('isUnixLikeName') self.assertEqual(v('abcd'), 1) - self.failUnless(v('a_123456'), 1) + self.assertTrue(v('a_123456'), 1) self.assertNotEqual(v('123'), 1) self.assertNotEqual(v('ab.c'), 1) self.assertEqual(v('ab,c'), u"Validation failed(isUnixLikeName): 'ab,c' this name is not a valid identifier") diff --git a/Products/validation/validators/RegexValidator.py b/Products/validation/validators/RegexValidator.py index fec27f6..62923b3 100644 --- a/Products/validation/validators/RegexValidator.py +++ b/Products/validation/validators/RegexValidator.py @@ -43,7 +43,7 @@ def __setstate__(self, dict): self.compileRegex() def __call__(self, value, *args, **kwargs): - if type(value) != six.binary_type: + if not isinstance(value, str): msg = _(u"Validation failed($name): $value of type $type, expected 'string'", mapping = { 'name' : safe_unicode(self.name), diff --git a/setup.py b/setup.py index 515e5dc..ae81845 100644 --- a/setup.py +++ b/setup.py @@ -1,24 +1,26 @@ from setuptools import setup, find_packages -version = '2.0.3.dev0' +version = '2.1.dev0' setup( name='Products.validation', version=version, - description="Data validation package for Archetypes", + description="Data validation package for Zope", long_description=(open("README.txt").read() + "\n" + open("CHANGES.txt").read()), classifiers=[ "Framework :: Zope2", "Operating System :: OS Independent", + "Framework :: Plone", "Framework :: Plone :: 4.3", "Framework :: Plone :: 5.0", "Framework :: Plone :: 5.1", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.5", ], - keywords='Zope catalog index', + keywords='Zope validation regex email', author='Benjamin Saller', author_email='plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org', url='https://pypi.python.org/pypi/Products.validation', ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot