2323 urllib3_wrap_socket = None
2424
2525
26- from mocket .compat import (
27- basestring ,
28- byte_type ,
29- decode_from_bytes ,
30- encode_to_bytes ,
31- text_type ,
32- )
26+ from mocket .compat import decode_from_bytes , encode_to_bytes
3327from mocket .utils import (
3428 MocketMode ,
3529 MocketSocketCore ,
@@ -323,7 +317,7 @@ def true_sendall(self, data, *args, **kwargs):
323317 # make request unique again
324318 req_signature = _hash_request (hasher , req )
325319 # port should be always a string
326- port = text_type (self ._port )
320+ port = str (self ._port )
327321
328322 # prepare responses dictionary
329323 responses = {}
@@ -433,7 +427,7 @@ class Mocket:
433427 _address = (None , None )
434428 _entries = collections .defaultdict (list )
435429 _requests = []
436- _namespace = text_type (id (_entries ))
430+ _namespace = str (id (_entries ))
437431 _truesocket_recording_dir = None
438432
439433 @classmethod
@@ -524,7 +518,7 @@ def enable(namespace=None, truesocket_recording_dir=None):
524518 socket .socketpair = socket .__dict__ ["socketpair" ] = socketpair
525519 ssl .wrap_socket = ssl .__dict__ ["wrap_socket" ] = FakeSSLContext .wrap_socket
526520 ssl .SSLContext = ssl .__dict__ ["SSLContext" ] = FakeSSLContext
527- socket .inet_pton = socket .__dict__ ["inet_pton" ] = lambda family , ip : byte_type (
521+ socket .inet_pton = socket .__dict__ ["inet_pton" ] = lambda family , ip : bytes (
528522 "\x7f \x00 \x00 \x01 " , "utf-8"
529523 )
530524 urllib3 .util .ssl_ .wrap_socket = urllib3 .util .ssl_ .__dict__ ["wrap_socket" ] = (
@@ -598,13 +592,13 @@ def assert_fail_if_entries_not_served(cls):
598592
599593
600594class MocketEntry :
601- class Response (byte_type ):
595+ class Response (bytes ):
602596 @property
603597 def data (self ):
604598 return self
605599
606600 response_index = 0
607- request_cls = byte_type
601+ request_cls = bytes
608602 response_cls = Response
609603 responses = None
610604 _served = None
@@ -613,9 +607,7 @@ def __init__(self, location, responses):
613607 self ._served = False
614608 self .location = location
615609
616- if not isinstance (responses , collections_abc .Iterable ) or isinstance (
617- responses , basestring
618- ):
610+ if not isinstance (responses , collections_abc .Iterable ):
619611 responses = [responses ]
620612
621613 if not responses :
@@ -624,7 +616,7 @@ def __init__(self, location, responses):
624616 self .responses = []
625617 for r in responses :
626618 if not isinstance (r , BaseException ) and not getattr (r , "data" , False ):
627- if isinstance (r , text_type ):
619+ if isinstance (r , str ):
628620 r = encode_to_bytes (r )
629621 r = self .response_cls (r )
630622 self .responses .append (r )
@@ -664,7 +656,7 @@ def __init__(
664656 ):
665657 self .instance = instance
666658 self .truesocket_recording_dir = truesocket_recording_dir
667- self .namespace = namespace or text_type (id (self ))
659+ self .namespace = namespace or str (id (self ))
668660 MocketMode ().STRICT = strict_mode
669661 if strict_mode :
670662 MocketMode ().STRICT_ALLOWED = strict_mode_allowed or []
0 commit comments