23
23
urllib3_wrap_socket = None
24
24
25
25
26
- from .compat import basestring , byte_type , decode_from_bytes , encode_to_bytes , text_type
27
- from .utils import (
26
+ from mocket .compat import decode_from_bytes , encode_to_bytes
27
+ from mocket .utils import (
28
28
MocketMode ,
29
29
MocketSocketCore ,
30
30
get_mocketize ,
@@ -317,7 +317,7 @@ def true_sendall(self, data, *args, **kwargs):
317
317
# make request unique again
318
318
req_signature = _hash_request (hasher , req )
319
319
# port should be always a string
320
- port = text_type (self ._port )
320
+ port = str (self ._port )
321
321
322
322
# prepare responses dictionary
323
323
responses = {}
@@ -427,7 +427,7 @@ class Mocket:
427
427
_address = (None , None )
428
428
_entries = collections .defaultdict (list )
429
429
_requests = []
430
- _namespace = text_type (id (_entries ))
430
+ _namespace = str (id (_entries ))
431
431
_truesocket_recording_dir = None
432
432
433
433
@classmethod
@@ -518,7 +518,7 @@ def enable(namespace=None, truesocket_recording_dir=None):
518
518
socket .socketpair = socket .__dict__ ["socketpair" ] = socketpair
519
519
ssl .wrap_socket = ssl .__dict__ ["wrap_socket" ] = FakeSSLContext .wrap_socket
520
520
ssl .SSLContext = ssl .__dict__ ["SSLContext" ] = FakeSSLContext
521
- socket .inet_pton = socket .__dict__ ["inet_pton" ] = lambda family , ip : byte_type (
521
+ socket .inet_pton = socket .__dict__ ["inet_pton" ] = lambda family , ip : bytes (
522
522
"\x7f \x00 \x00 \x01 " , "utf-8"
523
523
)
524
524
urllib3 .util .ssl_ .wrap_socket = urllib3 .util .ssl_ .__dict__ ["wrap_socket" ] = (
@@ -592,13 +592,13 @@ def assert_fail_if_entries_not_served(cls):
592
592
593
593
594
594
class MocketEntry :
595
- class Response (byte_type ):
595
+ class Response (bytes ):
596
596
@property
597
597
def data (self ):
598
598
return self
599
599
600
600
response_index = 0
601
- request_cls = byte_type
601
+ request_cls = bytes
602
602
response_cls = Response
603
603
responses = None
604
604
_served = None
@@ -607,9 +607,7 @@ def __init__(self, location, responses):
607
607
self ._served = False
608
608
self .location = location
609
609
610
- if not isinstance (responses , collections_abc .Iterable ) or isinstance (
611
- responses , basestring
612
- ):
610
+ if not isinstance (responses , collections_abc .Iterable ):
613
611
responses = [responses ]
614
612
615
613
if not responses :
@@ -618,7 +616,7 @@ def __init__(self, location, responses):
618
616
self .responses = []
619
617
for r in responses :
620
618
if not isinstance (r , BaseException ) and not getattr (r , "data" , False ):
621
- if isinstance (r , text_type ):
619
+ if isinstance (r , str ):
622
620
r = encode_to_bytes (r )
623
621
r = self .response_cls (r )
624
622
self .responses .append (r )
@@ -658,7 +656,7 @@ def __init__(
658
656
):
659
657
self .instance = instance
660
658
self .truesocket_recording_dir = truesocket_recording_dir
661
- self .namespace = namespace or text_type (id (self ))
659
+ self .namespace = namespace or str (id (self ))
662
660
MocketMode ().STRICT = strict_mode
663
661
if strict_mode :
664
662
MocketMode ().STRICT_ALLOWED = strict_mode_allowed or []
0 commit comments