23
23
urllib3_wrap_socket = None
24
24
25
25
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
33
27
from mocket .utils import (
34
28
MocketMode ,
35
29
MocketSocketCore ,
@@ -323,7 +317,7 @@ def true_sendall(self, data, *args, **kwargs):
323
317
# make request unique again
324
318
req_signature = _hash_request (hasher , req )
325
319
# port should be always a string
326
- port = text_type (self ._port )
320
+ port = str (self ._port )
327
321
328
322
# prepare responses dictionary
329
323
responses = {}
@@ -433,7 +427,7 @@ class Mocket:
433
427
_address = (None , None )
434
428
_entries = collections .defaultdict (list )
435
429
_requests = []
436
- _namespace = text_type (id (_entries ))
430
+ _namespace = str (id (_entries ))
437
431
_truesocket_recording_dir = None
438
432
439
433
@classmethod
@@ -524,7 +518,7 @@ def enable(namespace=None, truesocket_recording_dir=None):
524
518
socket .socketpair = socket .__dict__ ["socketpair" ] = socketpair
525
519
ssl .wrap_socket = ssl .__dict__ ["wrap_socket" ] = FakeSSLContext .wrap_socket
526
520
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 (
528
522
"\x7f \x00 \x00 \x01 " , "utf-8"
529
523
)
530
524
urllib3 .util .ssl_ .wrap_socket = urllib3 .util .ssl_ .__dict__ ["wrap_socket" ] = (
@@ -598,13 +592,13 @@ def assert_fail_if_entries_not_served(cls):
598
592
599
593
600
594
class MocketEntry :
601
- class Response (byte_type ):
595
+ class Response (bytes ):
602
596
@property
603
597
def data (self ):
604
598
return self
605
599
606
600
response_index = 0
607
- request_cls = byte_type
601
+ request_cls = bytes
608
602
response_cls = Response
609
603
responses = None
610
604
_served = None
@@ -613,9 +607,7 @@ def __init__(self, location, responses):
613
607
self ._served = False
614
608
self .location = location
615
609
616
- if not isinstance (responses , collections_abc .Iterable ) or isinstance (
617
- responses , basestring
618
- ):
610
+ if not isinstance (responses , collections_abc .Iterable ):
619
611
responses = [responses ]
620
612
621
613
if not responses :
@@ -624,7 +616,7 @@ def __init__(self, location, responses):
624
616
self .responses = []
625
617
for r in responses :
626
618
if not isinstance (r , BaseException ) and not getattr (r , "data" , False ):
627
- if isinstance (r , text_type ):
619
+ if isinstance (r , str ):
628
620
r = encode_to_bytes (r )
629
621
r = self .response_cls (r )
630
622
self .responses .append (r )
@@ -664,7 +656,7 @@ def __init__(
664
656
):
665
657
self .instance = instance
666
658
self .truesocket_recording_dir = truesocket_recording_dir
667
- self .namespace = namespace or text_type (id (self ))
659
+ self .namespace = namespace or str (id (self ))
668
660
MocketMode ().STRICT = strict_mode
669
661
if strict_mode :
670
662
MocketMode ().STRICT_ALLOWED = strict_mode_allowed or []
0 commit comments