Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)
Helper function.  Creates a listening socket on the designated
host and port.  Modeled on the socket.create_connection()
function.

        def _create_server(host, port):
    """
    Helper function.  Creates a listening socket on the designated
    host and port.  Modeled on the socket.create_connection()
    function.
    """

    exc = socket.error("getaddrinfo returns an empty list")
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
        af, socktype, proto, canonname, sa = res
        sock = None
        try:
            # Create the listening socket
            sock = socket.socket(af, socktype, proto)
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            sock.bind(sa)
            sock.listen(1024)
            return sock

        except socket.error as exc:
            # Clean up after ourselves
            if sock is not None:
                sock.close()

    # Couldn't create a listening socket
    raise exc
        


src/t/u/turnstile-HEAD/tests/unit/test_remote.py   turnstile(Download)
        ]
        mock_socket.side_effect = sockets
        result = remote._create_server('host', 'port')
        mock_getaddrinfo.assert_called_once_with('host', 'port', 0,
                                                 socket.SOCK_STREAM)