1
1
import base64
2
2
import numbers
3
- import six
4
3
import textwrap
5
4
import uuid
6
5
from importlib import import_module
14
13
# ----------------
15
14
import sys
16
15
16
+ from _plotly_utils .compat import str_types
17
+
17
18
np = None
18
19
pd = None
19
20
@@ -349,7 +350,7 @@ def __init__(self,
349
350
# ----------------------------
350
351
# Look for regular expressions
351
352
for v in self .values :
352
- if v and isinstance (v , str ) and v [0 ] == '/' and v [- 1 ] == '/' :
353
+ if v and isinstance (v , str_types ) and v [0 ] == '/' and v [- 1 ] == '/' :
353
354
# String is a regex with leading and trailing '/' character
354
355
regex_str = v [1 :- 1 ]
355
356
self .val_regexs .append (re .compile (regex_str ))
@@ -387,7 +388,7 @@ def perform_replacemenet(self, v):
387
388
"""
388
389
Return v with any applicable regex replacements applied
389
390
"""
390
- if isinstance (v , str ):
391
+ if isinstance (v , str_types ):
391
392
for repl_args in self .regex_replacements :
392
393
if repl_args :
393
394
v = re .sub (repl_args [0 ], repl_args [1 ], v )
@@ -442,7 +443,7 @@ def in_values(self, e):
442
443
"""
443
444
Return whether a value matches one of the enumeration options
444
445
"""
445
- is_str = isinstance (e , str )
446
+ is_str = isinstance (e , str_types )
446
447
for v , regex in zip (self .values , self .val_regexs ):
447
448
if is_str and regex :
448
449
in_values = fullmatch (regex , e ) is not None
@@ -821,7 +822,7 @@ def validate_coerce(self, v):
821
822
822
823
# If strict, make sure all elements are strings.
823
824
if self .strict :
824
- invalid_els = [e for e in v if not isinstance (e , str )]
825
+ invalid_els = [e for e in v if not isinstance (e , str_types )]
825
826
if invalid_els :
826
827
self .raise_invalid_elements (invalid_els )
827
828
@@ -862,10 +863,10 @@ def validate_coerce(self, v):
862
863
863
864
else :
864
865
if self .strict :
865
- if not isinstance (v , str ):
866
+ if not isinstance (v , str_types ):
866
867
self .raise_invalid_val (v )
867
868
else :
868
- if not isinstance (v , ( str , int , float )):
869
+ if not isinstance (v , str_types + ( int , float )):
869
870
self .raise_invalid_val (v )
870
871
871
872
# Convert value to a string
@@ -1081,7 +1082,7 @@ def perform_validate_coerce(v, allow_number=None):
1081
1082
if isinstance (v , numbers .Number ) and allow_number :
1082
1083
# If allow_numbers then any number is ok
1083
1084
return v
1084
- elif not isinstance (v , str ):
1085
+ elif not isinstance (v , str_types ):
1085
1086
# If not allow_numbers then value must be a string
1086
1087
return None
1087
1088
else :
@@ -1203,7 +1204,7 @@ def validate_coerce(self, v):
1203
1204
pass
1204
1205
if v is None :
1205
1206
v_valid = True
1206
- elif isinstance (v , str ):
1207
+ elif isinstance (v , str_types ):
1207
1208
v_match = [
1208
1209
el for el in ColorscaleValidator .named_colorscales
1209
1210
if el .lower () == v .lower ()
@@ -1218,7 +1219,7 @@ def validate_coerce(self, v):
1218
1219
len (e ) != 2 or
1219
1220
not isinstance (e [0 ], numbers .Number ) or
1220
1221
not (0 <= e [0 ] <= 1 ) or
1221
- not isinstance (e [1 ], str ) or
1222
+ not isinstance (e [1 ], str_types ) or
1222
1223
ColorValidator .perform_validate_coerce (e [1 ]) is None )]
1223
1224
1224
1225
if len (invalid_els ) == 0 :
@@ -1337,7 +1338,7 @@ def description(self):
1337
1338
def validate_coerce (self , v ):
1338
1339
if v is None :
1339
1340
pass
1340
- elif not isinstance (v , str ):
1341
+ elif not isinstance (v , str_types ):
1341
1342
self .raise_invalid_val (v )
1342
1343
else :
1343
1344
# match = re.fullmatch(self.regex, v)
@@ -1419,7 +1420,7 @@ def description(self):
1419
1420
return desc
1420
1421
1421
1422
def vc_scalar (self , v ):
1422
- if not isinstance (v , str ):
1423
+ if not isinstance (v , str_types ):
1423
1424
return None
1424
1425
1425
1426
# To be generous we accept flags separated on plus ('+'),
@@ -1660,7 +1661,7 @@ def description(self):
1660
1661
def validate_coerce (self , v ):
1661
1662
if v is None :
1662
1663
pass
1663
- elif isinstance (v , str ):
1664
+ elif isinstance (v , str_types ):
1664
1665
# Future possibilities:
1665
1666
# - Detect filesystem system paths and convert to URI
1666
1667
# - Validate either url or data uri
0 commit comments