Advertisement
lenkaseg

String Validator

Jan 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. String Validator from the pagure/validators.py:
  2.  
  3. class StringValidator(object):
  4.     """Validates input to be a string"""
  5.  
  6.     def __init__(self, message="This field needs to be a string"):
  7.         self._message = message
  8.  
  9.     def __call__(self, form, stringfield):
  10.         if type(stringfield.data) != six.text_type:
  11.             raise validators.ValidationError(
  12.                 "{0} Found {1}".format(self._message, stringfield.data)
  13.             )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement