コード例 #1
0
def test_accept():
    n = network.Network()
    n.add_server(PORT, AcceptServer)
    c = n.add_connection('localhost', PORT, network.Handler)  # random connection
    while c.is_open:
        n.service()
    n.close()
コード例 #2
0
ファイル: test_echo.py プロジェクト: robertchase/spindrift
def test_echo():
    n = network.Network()
    n.add_server(PORT, EchoServer)
    c = n.add_connection('localhost', PORT, EchoClient)
    while c.is_open:  # keep going until the client closes
        n.service()
    n.close()
コード例 #3
0
ファイル: test_ssl.py プロジェクト: robertchase/spindrift
def test_no_ssl_server():
    n = network.Network()
    n.add_server(PORT, PlainServer)  # non-ssl server
    c = n.add_connection('localhost', PORT, Client, is_ssl=True)  # ssl client
    while c.is_open:
        n.service()
    n.close()
    assert c.is_failed_handshake  # ends badly
コード例 #4
0
ファイル: test_ssl.py プロジェクト: robertchase/spindrift
def test_success():
    n = network.Network()
    n.add_server(PORT,
                 network.Handler,
                 is_ssl=True,
                 ssl_certfile='cert/cert.pem',
                 ssl_keyfile='cert/key.pem')  # self-signed certs
    c = n.add_connection('localhost', PORT, SuccessClient, is_ssl=True)
    while c.is_open:
        n.service()
    n.close()
    assert c.is_failed_handshake is False  # ssl handshake worked
コード例 #5
0
def test_server_compress():
    data = 'This is a TeSt'

    class _handler(http.HTTPHandler):
        def _send(self, headers, content):
            print(headers)
            self.tested = True
            assert content == gzip.compress(data.encode())

    handler = _handler(0, network.Network())
    handler.tested = False
    handler.http_send_server(data, gzip=True)
    assert handler.tested
コード例 #6
0
def test_echo():
    c = Context()
    n = network.Network()
    n.add_server(PORT, CountingHandler, context=c)
    cons = []
    cons.append(n.add_connection('localhost', PORT, network.Handler))
    cons.append(n.add_connection('localhost', PORT, network.Handler))
    cons.append(n.add_connection('localhost', PORT, network.Handler))
    cons.append(n.add_connection('localhost', PORT, network.Handler))
    cons.append(n.add_connection('localhost', PORT, network.Handler))

    # keep going while any client connection is open
    while functools.reduce(operator.__or__, (c.is_open for c in cons), False):
        n.service()
    n.close()

    assert c.counter == len(cons)  # every connection counted once
コード例 #7
0
def test_gzip():
    handler = http.HTTPHandler(0, network.Network())
    data = b'This Is A Test'
    zdata = gzip.compress(data)
    handler.http_content = zdata

    handler._on_http_data()
    assert handler.http_content == zdata

    handler.http_headers = {'content-encoding': 'gzip'}
    handler._on_http_data()
    assert handler.http_content == data

    handler.http_headers['content-type'] = 'text/html; charset=utf-8'
    handler.http_content = zdata
    handler._on_http_data()
    assert handler.http_content == data.decode()
コード例 #8
0
ファイル: https_google.py プロジェクト: robertchase/spindrift
import spindrift.network as network

from example.http_google import Google

n = network.Network()
c = n.add_connection('www.google.com', 443, Google, is_ssl=True)
while c.is_open:
    n.service()
コード例 #9
0
def net(ctx):
    n = network.Network()
    n.add_server(PORT, Server, context=ctx)
    yield n
    n.close()