コード例 #1
0
ファイル: tcp_mojifinder.py プロジェクト: hjlarry/practise-py
def main(host: str = "127.0.0.1", port_arg: str = "2323"):
    port = int(port_arg)
    print("Building Index.")
    index = InvertedIndex()
    try:
        asyncio.run(supervisor(index, host, port))
    except KeyboardInterrupt:
        print("serving shut down")
コード例 #2
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)
コード例 #3
0
def main(host: str = '127.0.0.1', port_arg: str = '2323'):
    port = int(port_arg)
    print('Building index.')
    index = InvertedIndex()  # <7>
    try:
        asyncio.run(supervisor(index, host, port))  # <8>
    except KeyboardInterrupt:  # <9>
        print('\nServer shut down.')
コード例 #4
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)
コード例 #5
0
def init(app):  # <3>
    app.state.index = InvertedIndex()
    static = pathlib.Path(__file__).parent.absolute() / 'static'
    with open(static / 'form.html') as fp:
        app.state.form = fp.read()
コード例 #6
0
def init(app):
    app.state.index = InvertedIndex()
    app.state.form = (Path(__file__).parent /
                      "http_mojifinder.html").read_text()
コード例 #7
0
def main(port):
    global index
    index = InvertedIndex()
    run(host='localhost', port=port, debug=True)
コード例 #8
0
def init(app):  # <3>
    app.state.index = InvertedIndex()
    static = Path(__file__).parent.absolute() / 'static'  # <4>
    app.state.form = (static / 'form.html').read_text()