@@ -170,13 +170,6 @@ def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]],
170
170
return None
171
171
172
172
173
- try :
174
- basestring # type: ignore
175
- unicode_str = unicode # type: ignore
176
- except NameError :
177
- basestring = str
178
- unicode_str = str
179
-
180
173
_LOGGER = logging .getLogger (__name__ )
181
174
182
175
try :
@@ -545,7 +538,7 @@ class Serializer(object):
545
538
"multiple" : lambda x , y : x % y != 0 ,
546
539
}
547
540
548
- def __init__ (self , classes : Optional [Mapping [str , Type [ ModelType ] ]] = None ):
541
+ def __init__ (self , classes : Optional [Mapping [str , type ]] = None ):
549
542
self .serialize_type = {
550
543
"iso-8601" : Serializer .serialize_iso ,
551
544
"rfc-1123" : Serializer .serialize_rfc ,
@@ -561,7 +554,7 @@ def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
561
554
"[]" : self .serialize_iter ,
562
555
"{}" : self .serialize_dict ,
563
556
}
564
- self .dependencies : Dict [str , Type [ ModelType ] ] = dict (classes ) if classes else {}
557
+ self .dependencies : Dict [str , type ] = dict (classes ) if classes else {}
565
558
self .key_transformer = full_restapi_key_transformer
566
559
self .client_side_validation = True
567
560
@@ -649,7 +642,7 @@ def _serialize(self, target_obj, data_type=None, **kwargs):
649
642
else : # That's a basic type
650
643
# Integrate namespace if necessary
651
644
local_node = _create_xml_node (xml_name , xml_prefix , xml_ns )
652
- local_node .text = unicode_str (new_attr )
645
+ local_node .text = str (new_attr )
653
646
serialized .append (local_node ) # type: ignore
654
647
else : # JSON
655
648
for k in reversed (keys ): # type: ignore
@@ -994,7 +987,7 @@ def serialize_object(self, attr, **kwargs):
994
987
return self .serialize_basic (attr , self .basic_types [obj_type ], ** kwargs )
995
988
if obj_type is _long_type :
996
989
return self .serialize_long (attr )
997
- if obj_type is unicode_str :
990
+ if obj_type is str :
998
991
return self .serialize_unicode (attr )
999
992
if obj_type is datetime .datetime :
1000
993
return self .serialize_iso (attr )
@@ -1370,7 +1363,7 @@ class Deserializer(object):
1370
1363
1371
1364
valid_date = re .compile (r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}" r"\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?" )
1372
1365
1373
- def __init__ (self , classes : Optional [Mapping [str , Type [ ModelType ] ]] = None ):
1366
+ def __init__ (self , classes : Optional [Mapping [str , type ]] = None ):
1374
1367
self .deserialize_type = {
1375
1368
"iso-8601" : Deserializer .deserialize_iso ,
1376
1369
"rfc-1123" : Deserializer .deserialize_rfc ,
@@ -1390,7 +1383,7 @@ def __init__(self, classes: Optional[Mapping[str, Type[ModelType]]] = None):
1390
1383
"duration" : (isodate .Duration , datetime .timedelta ),
1391
1384
"iso-8601" : (datetime .datetime ),
1392
1385
}
1393
- self .dependencies : Dict [str , Type [ ModelType ] ] = dict (classes ) if classes else {}
1386
+ self .dependencies : Dict [str , type ] = dict (classes ) if classes else {}
1394
1387
self .key_extractors = [rest_key_extractor , xml_key_extractor ]
1395
1388
# Additional properties only works if the "rest_key_extractor" is used to
1396
1389
# extract the keys. Making it to work whatever the key extractor is too much
@@ -1443,7 +1436,7 @@ def _deserialize(self, target_obj, data):
1443
1436
1444
1437
response , class_name = self ._classify_target (target_obj , data )
1445
1438
1446
- if isinstance (response , basestring ):
1439
+ if isinstance (response , str ):
1447
1440
return self .deserialize_data (data , response )
1448
1441
elif isinstance (response , type ) and issubclass (response , Enum ):
1449
1442
return self .deserialize_enum (data , response )
@@ -1514,14 +1507,14 @@ def _classify_target(self, target, data):
1514
1507
if target is None :
1515
1508
return None , None
1516
1509
1517
- if isinstance (target , basestring ):
1510
+ if isinstance (target , str ):
1518
1511
try :
1519
1512
target = self .dependencies [target ]
1520
1513
except KeyError :
1521
1514
return target , target
1522
1515
1523
1516
try :
1524
- target = target ._classify (data , self .dependencies )
1517
+ target = target ._classify (data , self .dependencies ) # type: ignore
1525
1518
except AttributeError :
1526
1519
pass # Target is not a Model, no classify
1527
1520
return target , target .__class__ .__name__ # type: ignore
@@ -1577,7 +1570,7 @@ def _unpack_content(raw_data, content_type=None):
1577
1570
if hasattr (raw_data , "_content_consumed" ):
1578
1571
return RawDeserializer .deserialize_from_http_generics (raw_data .text , raw_data .headers )
1579
1572
1580
- if isinstance (raw_data , (basestring , bytes )) or hasattr (raw_data , "read" ):
1573
+ if isinstance (raw_data , (str , bytes )) or hasattr (raw_data , "read" ):
1581
1574
return RawDeserializer .deserialize_from_text (raw_data , content_type ) # type: ignore
1582
1575
return raw_data
1583
1576
@@ -1699,7 +1692,7 @@ def deserialize_object(self, attr, **kwargs):
1699
1692
if isinstance (attr , ET .Element ):
1700
1693
# Do no recurse on XML, just return the tree as-is
1701
1694
return attr
1702
- if isinstance (attr , basestring ):
1695
+ if isinstance (attr , str ):
1703
1696
return self .deserialize_basic (attr , "str" )
1704
1697
obj_type = type (attr )
1705
1698
if obj_type in self .basic_types :
@@ -1756,7 +1749,7 @@ def deserialize_basic(self, attr, data_type):
1756
1749
if data_type == "bool" :
1757
1750
if attr in [True , False , 1 , 0 ]:
1758
1751
return bool (attr )
1759
- elif isinstance (attr , basestring ):
1752
+ elif isinstance (attr , str ):
1760
1753
if attr .lower () in ["true" , "1" ]:
1761
1754
return True
1762
1755
elif attr .lower () in ["false" , "0" ]:
0 commit comments