1
1
# This module is define and keep all generic type of data-validations.
2
+ import six
2
3
import re
3
4
from voluptuous import Invalid
4
5
from django .utils .dateparse import parse_datetime , parse_date
@@ -15,10 +16,10 @@ def IntegerLike(msg=None):
15
16
def fn (value ):
16
17
if not (
17
18
isinstance (value , int ) or
18
- isinstance (value , long ) or
19
19
(isinstance (value , float ) and value .is_integer ()) or
20
20
(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 )
22
23
):
23
24
raise Invalid (msg or (
24
25
'Invalid input <{0}>; expected an integer' .format (value ))
@@ -39,10 +40,10 @@ def Alphanumeric(msg=None):
39
40
def fn (value ):
40
41
if not (
41
42
isinstance (value , int ) or
42
- isinstance (value , long ) or
43
43
(isinstance (value , float ) and value .is_integer ()) or
44
44
(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 )
46
47
):
47
48
raise Invalid (msg or (
48
49
'Invalid input <{0}>; expected an integer' .format (value ))
@@ -64,7 +65,7 @@ def StrictlyAlphanumeric(msg=None):
64
65
'''
65
66
def fn (value ):
66
67
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
68
69
re_alphabets .search (value ) and
69
70
re_digits .search (value )
70
71
):
@@ -101,15 +102,15 @@ def CSVofIntegers(msg=None):
101
102
'''
102
103
def fn (value ):
103
104
try :
104
- if isinstance (value , unicode ):
105
+ if isinstance (value , six . text_type ):
105
106
if ',' in value :
106
- value = map (
107
+ value = list ( map (
107
108
int , filter (
108
- bool , map (
109
+ bool , list ( map (
109
110
lambda x : x .strip (), value .split (',' )
110
- )
111
+ ))
111
112
)
112
- )
113
+ ))
113
114
return value
114
115
else :
115
116
return [int (value )]
0 commit comments