|
51 | 51 | true_gethostbyname = socket.gethostbyname |
52 | 52 | true_gethostname = socket.gethostname |
53 | 53 | true_getaddrinfo = socket.getaddrinfo |
| 54 | +true_socketpair = socket.socketpair |
54 | 55 | true_ssl_wrap_socket = ssl.wrap_socket |
55 | 56 | true_ssl_socket = ssl.SSLSocket |
56 | 57 | true_ssl_context = ssl.SSLContext |
@@ -136,6 +137,13 @@ def create_connection(address, timeout=None, source_address=None): |
136 | 137 | return s |
137 | 138 |
|
138 | 139 |
|
| 140 | +def socketpair(): |
| 141 | + """Returns a real socketpair() used by asyncio loop for supporting calls made by fastapi and similar services.""" |
| 142 | + import _socket |
| 143 | + |
| 144 | + return _socket.socketpair() |
| 145 | + |
| 146 | + |
139 | 147 | def _hash_request(h, req): |
140 | 148 | return h(encode_to_bytes("".join(sorted(req.split("\r\n"))))).hexdigest() |
141 | 149 |
|
@@ -488,6 +496,7 @@ def enable(namespace=None, truesocket_recording_dir=None): |
488 | 496 | ] = lambda host, port, family=None, socktype=None, proto=None, flags=None: [ |
489 | 497 | (2, 1, 6, "", (host, port)) |
490 | 498 | ] |
| 499 | + socket.socketpair = socket.__dict__["socketpair"] = socketpair |
491 | 500 | ssl.wrap_socket = ssl.__dict__["wrap_socket"] = FakeSSLContext.wrap_socket |
492 | 501 | ssl.SSLContext = ssl.__dict__["SSLContext"] = FakeSSLContext |
493 | 502 | socket.inet_pton = socket.__dict__["inet_pton"] = lambda family, ip: byte_type( |
@@ -520,6 +529,7 @@ def disable(): |
520 | 529 | socket.gethostname = socket.__dict__["gethostname"] = true_gethostname |
521 | 530 | socket.gethostbyname = socket.__dict__["gethostbyname"] = true_gethostbyname |
522 | 531 | socket.getaddrinfo = socket.__dict__["getaddrinfo"] = true_getaddrinfo |
| 532 | + socket.socketpair = socket.__dict__["socketpair"] = true_socketpair |
523 | 533 | ssl.wrap_socket = ssl.__dict__["wrap_socket"] = true_ssl_wrap_socket |
524 | 534 | ssl.SSLContext = ssl.__dict__["SSLContext"] = true_ssl_context |
525 | 535 | socket.inet_pton = socket.__dict__["inet_pton"] = true_inet_pton |
|
0 commit comments