示例#1
0
def ss_reader(cipher):
    parser = yield from iofree.get_parser()
    iv = yield from iofree.read(cipher.IV_SIZE)
    decrypt = cipher.make_decrypter(iv)
    while True:
        data = yield from iofree.read_more()
        parser.write(decrypt(data))
示例#2
0
def bad_reader():
    with pytest.raises(ValueError):
        yield from iofree.read_more(-1)
    with pytest.raises(ValueError):
        yield from iofree.peek(-1)
    with pytest.raises(ValueError):
        yield from iofree.read_int(-1)

    yield from iofree.wait()
    yield "bad"
示例#3
0
def http_response():
    response = yield from HTTPResponse
    assert response.ver == b"HTTP/1.1"
    assert response.code == b"200"
    assert response.status == b"OK"
    yield from iofree.read_until(b"\n", return_tail=True)
    data = yield from iofree.read(4)
    assert data == b"haha"
    (number, ) = yield from iofree.read_struct("!H")
    assert number == 8 * 256 + 8
    number = yield from iofree.read_int(3)
    assert number == int.from_bytes(b"\x11\x11\x11", "big")
    assert (yield from iofree.peek(2)) == b"co"
    assert (yield from iofree.read(7)) == b"content"
    yield from iofree.wait()
    assert len((yield from iofree.read_more(5))) >= 5
    yield from iofree.read()
    yield from iofree.wait_event()
    return b"\r\n".join(response.header_lines)