Improve PEP8 gluon/validators.py
This commit is contained in:
+20
-10
@@ -348,6 +348,7 @@ class IS_LENGTH(Validator):
|
|||||||
return (value, translate(self.error_message)
|
return (value, translate(self.error_message)
|
||||||
% dict(min=self.minsize, max=self.maxsize))
|
% dict(min=self.minsize, max=self.maxsize))
|
||||||
|
|
||||||
|
|
||||||
class IS_JSON(Validator):
|
class IS_JSON(Validator):
|
||||||
"""
|
"""
|
||||||
Example:
|
Example:
|
||||||
@@ -696,7 +697,7 @@ class IS_NOT_IN_DB(Validator):
|
|||||||
|
|
||||||
|
|
||||||
def range_error_message(error_message, what_to_enter, minimum, maximum):
|
def range_error_message(error_message, what_to_enter, minimum, maximum):
|
||||||
"build the error message for the number range validators"
|
"""build the error message for the number range validators"""
|
||||||
if error_message is None:
|
if error_message is None:
|
||||||
error_message = 'Enter ' + what_to_enter
|
error_message = 'Enter ' + what_to_enter
|
||||||
if minimum is not None and maximum is not None:
|
if minimum is not None and maximum is not None:
|
||||||
@@ -938,7 +939,7 @@ class IS_DECIMAL_IN_RANGE(Validator):
|
|||||||
|
|
||||||
|
|
||||||
def is_empty(value, empty_regex=None):
|
def is_empty(value, empty_regex=None):
|
||||||
"test empty field"
|
"""test empty field"""
|
||||||
if isinstance(value, (str, unicode)):
|
if isinstance(value, (str, unicode)):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
if empty_regex is not None and empty_regex.match(value):
|
if empty_regex is not None and empty_regex.match(value):
|
||||||
@@ -1153,6 +1154,7 @@ class IS_EMAIL(Validator):
|
|||||||
return (value, None)
|
return (value, None)
|
||||||
return (value, translate(self.error_message))
|
return (value, translate(self.error_message))
|
||||||
|
|
||||||
|
|
||||||
class IS_LIST_OF_EMAILS(object):
|
class IS_LIST_OF_EMAILS(object):
|
||||||
"""
|
"""
|
||||||
Example:
|
Example:
|
||||||
@@ -1166,6 +1168,7 @@ class IS_LIST_OF_EMAILS(object):
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
split_emails = re.compile('[^,;\s]+')
|
split_emails = re.compile('[^,;\s]+')
|
||||||
|
|
||||||
def __init__(self, error_message='Invalid emails: %s'):
|
def __init__(self, error_message='Invalid emails: %s'):
|
||||||
self.error_message = error_message
|
self.error_message = error_message
|
||||||
|
|
||||||
@@ -1334,7 +1337,7 @@ label_split_regex = re.compile(u'[\u002e\u3002\uff0e\uff61]')
|
|||||||
|
|
||||||
|
|
||||||
def escape_unicode(string):
|
def escape_unicode(string):
|
||||||
'''
|
"""
|
||||||
Converts a unicode string into US-ASCII, using a simple conversion scheme.
|
Converts a unicode string into US-ASCII, using a simple conversion scheme.
|
||||||
Each unicode character that does not have a US-ASCII equivalent is
|
Each unicode character that does not have a US-ASCII equivalent is
|
||||||
converted into a URL escaped form based on its hexadecimal value.
|
converted into a URL escaped form based on its hexadecimal value.
|
||||||
@@ -1348,7 +1351,7 @@ def escape_unicode(string):
|
|||||||
string: the US-ASCII escaped form of the inputted string
|
string: the US-ASCII escaped form of the inputted string
|
||||||
|
|
||||||
@author: Jonathan Benn
|
@author: Jonathan Benn
|
||||||
'''
|
"""
|
||||||
returnValue = StringIO()
|
returnValue = StringIO()
|
||||||
|
|
||||||
for character in string:
|
for character in string:
|
||||||
@@ -1363,7 +1366,7 @@ def escape_unicode(string):
|
|||||||
|
|
||||||
|
|
||||||
def unicode_to_ascii_authority(authority):
|
def unicode_to_ascii_authority(authority):
|
||||||
'''
|
"""
|
||||||
Follows the steps in RFC 3490, Section 4 to convert a unicode authority
|
Follows the steps in RFC 3490, Section 4 to convert a unicode authority
|
||||||
string into its ASCII equivalent.
|
string into its ASCII equivalent.
|
||||||
For example, u'www.Alliancefran\xe7aise.nu' will be converted into
|
For example, u'www.Alliancefran\xe7aise.nu' will be converted into
|
||||||
@@ -1382,7 +1385,7 @@ def unicode_to_ascii_authority(authority):
|
|||||||
authority
|
authority
|
||||||
|
|
||||||
@author: Jonathan Benn
|
@author: Jonathan Benn
|
||||||
'''
|
"""
|
||||||
# RFC 3490, Section 4, Step 1
|
# RFC 3490, Section 4, Step 1
|
||||||
# The encodings.idna Python module assumes that AllowUnassigned == True
|
# The encodings.idna Python module assumes that AllowUnassigned == True
|
||||||
|
|
||||||
@@ -1413,7 +1416,7 @@ def unicode_to_ascii_authority(authority):
|
|||||||
|
|
||||||
|
|
||||||
def unicode_to_ascii_url(url, prepend_scheme):
|
def unicode_to_ascii_url(url, prepend_scheme):
|
||||||
'''
|
"""
|
||||||
Converts the inputed unicode url into a US-ASCII equivalent. This function
|
Converts the inputed unicode url into a US-ASCII equivalent. This function
|
||||||
goes a little beyond RFC 3490, which is limited in scope to the domain name
|
goes a little beyond RFC 3490, which is limited in scope to the domain name
|
||||||
(authority) only. Here, the functionality is expanded to what was observed
|
(authority) only. Here, the functionality is expanded to what was observed
|
||||||
@@ -1443,7 +1446,7 @@ def unicode_to_ascii_url(url, prepend_scheme):
|
|||||||
string: a US-ASCII equivalent of the inputed url
|
string: a US-ASCII equivalent of the inputed url
|
||||||
|
|
||||||
@author: Jonathan Benn
|
@author: Jonathan Benn
|
||||||
'''
|
"""
|
||||||
# convert the authority component of the URL into an ASCII punycode string,
|
# convert the authority component of the URL into an ASCII punycode string,
|
||||||
# but encode the rest using the regular URI character encoding
|
# but encode the rest using the regular URI character encoding
|
||||||
|
|
||||||
@@ -2120,7 +2123,7 @@ class IS_TIME(Validator):
|
|||||||
if not value.group('s') is None:
|
if not value.group('s') is None:
|
||||||
s = int(value.group('s'))
|
s = int(value.group('s'))
|
||||||
if value.group('d') == 'pm' and 0 < h < 12:
|
if value.group('d') == 'pm' and 0 < h < 12:
|
||||||
h = h + 12
|
h += 12
|
||||||
if value.group('d') == 'am' and h == 12:
|
if value.group('d') == 'am' and h == 12:
|
||||||
h = 0
|
h = 0
|
||||||
if not (h in range(24) and m in range(60) and s
|
if not (h in range(24) and m in range(60) and s
|
||||||
@@ -2134,18 +2137,23 @@ class IS_TIME(Validator):
|
|||||||
pass
|
pass
|
||||||
return (ivalue, translate(self.error_message))
|
return (ivalue, translate(self.error_message))
|
||||||
|
|
||||||
|
|
||||||
# A UTC class.
|
# A UTC class.
|
||||||
class UTC(datetime.tzinfo):
|
class UTC(datetime.tzinfo):
|
||||||
"""UTC"""
|
"""UTC"""
|
||||||
ZERO = datetime.timedelta(0)
|
ZERO = datetime.timedelta(0)
|
||||||
|
|
||||||
def utcoffset(self, dt):
|
def utcoffset(self, dt):
|
||||||
return UTC.ZERO
|
return UTC.ZERO
|
||||||
|
|
||||||
def tzname(self, dt):
|
def tzname(self, dt):
|
||||||
return "UTC"
|
return "UTC"
|
||||||
|
|
||||||
def dst(self, dt):
|
def dst(self, dt):
|
||||||
return UTC.ZERO
|
return UTC.ZERO
|
||||||
utc = UTC()
|
utc = UTC()
|
||||||
|
|
||||||
|
|
||||||
class IS_DATE(Validator):
|
class IS_DATE(Validator):
|
||||||
"""
|
"""
|
||||||
Examples:
|
Examples:
|
||||||
@@ -2735,6 +2743,7 @@ class LazyCrypt(object):
|
|||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return not self.__eq__(other)
|
return not self.__eq__(other)
|
||||||
|
|
||||||
|
|
||||||
class CRYPT(object):
|
class CRYPT(object):
|
||||||
"""
|
"""
|
||||||
Examples:
|
Examples:
|
||||||
@@ -2852,7 +2861,7 @@ otherset = frozenset(
|
|||||||
|
|
||||||
|
|
||||||
def calc_entropy(string):
|
def calc_entropy(string):
|
||||||
" calculates a simple entropy for a given string "
|
""" calculates a simple entropy for a given string """
|
||||||
import math
|
import math
|
||||||
alphabet = 0 # alphabet size
|
alphabet = 0 # alphabet size
|
||||||
other = set()
|
other = set()
|
||||||
@@ -3374,6 +3383,7 @@ class IS_IPV4(Validator):
|
|||||||
return (value, None)
|
return (value, None)
|
||||||
return (value, translate(self.error_message))
|
return (value, translate(self.error_message))
|
||||||
|
|
||||||
|
|
||||||
class IS_IPV6(Validator):
|
class IS_IPV6(Validator):
|
||||||
"""
|
"""
|
||||||
Checks if field's value is an IP version 6 address. First attempts to
|
Checks if field's value is an IP version 6 address. First attempts to
|
||||||
|
|||||||
Reference in New Issue
Block a user