MCPcopy
hub / github.com/aio-libs/aiohttp / create_connection

Function create_connection

tests/test_connector.py:780–856  ·  view source on GitHub ↗
(*args, **kwargs)

Source from the content-addressed store, hash-verified

778 return mock_socket
779
780 async def create_connection(*args, **kwargs):
781 nonlocal os_error, certificate_error, ssl_error, fingerprint_error
782 nonlocal connected
783
784 sock = kwargs["sock"]
785 addr_info = sock.getpeername()
786 ip = addr_info[0]
787
788 ips_tried.append(ip)
789
790 if ip == ip1:
791 os_error = True
792 raise OSError
793
794 if ip == ip2:
795 certificate_error = True
796 raise ssl.CertificateError
797
798 if ip == ip3:
799 ssl_error = True
800 raise ssl.SSLError
801
802 if ip == ip4:
803 sock: socket.socket = kwargs["sock"]
804
805 # Close the socket since we are not actually connecting
806 # and we don't want to leak it.
807 sock.close()
808
809 fingerprint_error = True
810 tr, pr = mock.Mock(), mock.Mock()
811
812 def get_extra_info(param):
813 if param == "sslcontext":
814 return True
815
816 if param == "ssl_object":
817 s = mock.Mock()
818 s.getpeercert.return_value = b"not foo"
819 return s
820
821 if param == "peername":
822 return ("192.168.1.5", 12345)
823
824 if param == "socket":
825 return sock
826
827 assert False, param
828
829 tr.get_extra_info = get_extra_info
830 return tr, pr
831
832 if ip == ip5:
833 sock: socket.socket = kwargs["sock"]
834
835 # Close the socket since we are not actually connecting
836 # and we don't want to leak it.
837 sock.close()

Callers

nothing calls this directly

Calls 3

appendMethod · 0.80
create_mocked_connFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…