[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Validators - MultiSelectionValidator.py:1.1.2.3 StringBaseValidator.py:1.1.2.3
Martijn Pieters
mj@zope.com
Wed, 13 Feb 2002 00:03:35 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator/Validators
In directory cvs.zope.org:/tmp/cvs-serv14206/App/Formulator/Validators
Modified Files:
Tag: Zope-3x-branch
MultiSelectionValidator.py StringBaseValidator.py
Log Message:
Optimizations and code style updates:
- Use isinstance on type checks
- Test UnicodeType and StringType through StringTypes
- Remove use of the string module
- Use startswith and endswith instead of slices.
- Fix weird tests where isinstance suffices.
=== Zope3/lib/python/Zope/App/Formulator/Validators/MultiSelectionValidator.py 1.1.2.2 => 1.1.2.3 ===
from Validator import Validator
-
+from types import ListType
class MultiSelectionValidator(Validator):
""" """
@@ -37,7 +37,7 @@
def validate(self, field, value):
values = value
# NOTE: a hack to deal with single item selections
- if type(values) is not type([]):
+ if not isinstance(values, ListType):
# put whatever we got in a list
values = [values]
=== Zope3/lib/python/Zope/App/Formulator/Validators/StringBaseValidator.py 1.1.2.2 => 1.1.2.3 ===
from Validator import Validator
+from types import StringType
class StringBaseValidator(Validator):
@@ -33,7 +34,7 @@
def validate(self, field, value):
""" """
- if type(value) != type(''):
+ if not isinstance(value, StringType):
self.raiseError('illegalValue', field)
value = value.strip()
if field.getValue('isRequired') and value == "":