コード例 #1
0
ファイル: tcp_mojifinder.py プロジェクト: hjlarry/practise-py
async def search(query: str, index: InvertedIndex, writer: asyncio.StreamWriter) -> int:
    chars = index.search(query)
    lines = (line.encode() + CRLF for line in format_results(chars))
    writer.writelines(lines)
    await writer.drain()
    writer.write(f"{'-'*66}".encode() + CRLF + f"{len(chars)} founded".encode() + CRLF)
    await writer.drain()
    return len(chars)
コード例 #2
0
async def search(
        query: str,  # <1>
        index: InvertedIndex,
        writer: asyncio.StreamWriter) -> int:
    chars = index.search(query)  # <2>
    lines = (
        line.encode() + CRLF for line  # <3>
        in format_results(chars))
    writer.writelines(lines)  # <4>
    await writer.drain()  # <5>
    status_line = f'{"─" * 66} {len(chars)} found'  # <6>
    writer.write(status_line.encode() + CRLF)
    await writer.drain()
    return len(chars)