11# This module is define and keep all generic type of data-validations.
2+ import six
23import re
34from voluptuous import Invalid
45from django .utils .dateparse import parse_datetime , parse_date
@@ -15,10 +16,10 @@ def IntegerLike(msg=None):
1516 def fn (value ):
1617 if not (
1718 isinstance (value , int ) or
18- isinstance (value , long ) or
1919 (isinstance (value , float ) and value .is_integer ()) or
2020 (isinstance (value , str ) and value .isdigit ()) or
21- (isinstance (value , unicode ) and value .isdigit ())
21+ ((isinstance (value , unicode ) and value .isdigit () or
22+ isinstance (value , long )) if six .PY2 else None )
2223 ):
2324 raise Invalid (msg or (
2425 'Invalid input <{0}>; expected an integer' .format (value ))
@@ -39,10 +40,10 @@ def Alphanumeric(msg=None):
3940 def fn (value ):
4041 if not (
4142 isinstance (value , int ) or
42- isinstance (value , long ) or
4343 (isinstance (value , float ) and value .is_integer ()) or
4444 (isinstance (value , str ) and value .isalnum ()) or
45- (isinstance (value , unicode ) and value .isalnum ())
45+ ((isinstance (value , unicode ) and value .isdigit () or
46+ isinstance (value , long )) if six .PY2 else None )
4647 ):
4748 raise Invalid (msg or (
4849 'Invalid input <{0}>; expected an integer' .format (value ))
@@ -64,7 +65,7 @@ def StrictlyAlphanumeric(msg=None):
6465 '''
6566 def fn (value ):
6667 if not (
67- (isinstance (value , str ) or isinstance (value , unicode )) and
68+ (isinstance (value , str ) or ( isinstance (value , unicode ) if six . PY2 else None )) and
6869 re_alphabets .search (value ) and
6970 re_digits .search (value )
7071 ):
@@ -101,15 +102,15 @@ def CSVofIntegers(msg=None):
101102 '''
102103 def fn (value ):
103104 try :
104- if isinstance (value , unicode ):
105+ if isinstance (value , six . text_type ):
105106 if ',' in value :
106- value = map (
107+ value = list ( map (
107108 int , filter (
108- bool , map (
109+ bool , list ( map (
109110 lambda x : x .strip (), value .split (',' )
110- )
111+ ))
111112 )
112- )
113+ ))
113114 return value
114115 else :
115116 return [int (value )]
0 commit comments