diff options
author | Karl MacMillan <kmacmill@redhat.com> | 2007-12-11 12:42:51 -0500 |
---|---|---|
committer | Karl MacMillan <kmacmill@redhat.com> | 2007-12-11 12:42:51 -0500 |
commit | ad3fcc200c88a5b4d5502c1f5415f72d293ae581 (patch) | |
tree | 19ceac36f79d7cdc874abbd7ca9c985bec957e63 /ipa-python/ipavalidate.py | |
parent | d2378f13d0ce867175952346302d42c7a9a9fb2b (diff) | |
parent | ca8e71d9381fb61368e5666c4d560ae9417fdf97 (diff) | |
download | freeipa-ad3fcc200c88a5b4d5502c1f5415f72d293ae581.tar.gz freeipa-ad3fcc200c88a5b4d5502c1f5415f72d293ae581.tar.xz freeipa-ad3fcc200c88a5b4d5502c1f5415f72d293ae581.zip |
Merge.
Diffstat (limited to 'ipa-python/ipavalidate.py')
-rw-r--r-- | ipa-python/ipavalidate.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/ipa-python/ipavalidate.py b/ipa-python/ipavalidate.py index 3a6699e16..36d94e02d 100644 --- a/ipa-python/ipavalidate.py +++ b/ipa-python/ipavalidate.py @@ -19,7 +19,7 @@ import re -def email(mail, notEmpty=True): +def Email(mail, notEmpty=True): """Do some basic validation of an e-mail address. Return 0 if ok Return 1 if not @@ -49,7 +49,7 @@ def email(mail, notEmpty=True): return 0 -def plain(text, notEmpty=False): +def Plain(text, notEmpty=False, allowSpaces=True): """Do some basic validation of a plain text field Return 0 if ok Return 1 if not @@ -57,23 +57,33 @@ def plain(text, notEmpty=False): If notEmpty is True the this will return an error if the field is "" or None. """ - textRE = re.compile(r"^[a-zA-Z_\-0-9\'\ ]*$") - - if not text and notEmpty is True: - return 1 - - if text is None: + if (text is None) or (not text.strip()): if notEmpty is True: return 1 else: return 0 + if allowSpaces: + textRE = re.compile(r"^[a-zA-Z_\-0-9\'\ ]*$") + else: + textRE = re.compile(r"^[a-zA-Z_\-0-9\']*$") if not textRE.search(text): return 1 return 0 -def path(text, notEmpty=False): +def String(text, notEmpty=False): + """A string type. This is much looser in what it allows than plain""" + + if text is None or not text.strip(): + if notEmpty is True: + return 1 + else: + return 0 + + return 0 + +def Path(text, notEmpty=False): """Do some basic validation of a path Return 0 if ok Return 1 if not |