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")
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)
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.')
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)
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()
def init(app): app.state.index = InvertedIndex() app.state.form = (Path(__file__).parent / "http_mojifinder.html").read_text()
def main(port): global index index = InvertedIndex() run(host='localhost', port=port, debug=True)
def init(app): # <3> app.state.index = InvertedIndex() static = Path(__file__).parent.absolute() / 'static' # <4> app.state.form = (static / 'form.html').read_text()