def request_paragraph(data): """Return a random paragraph.""" paragraphs = typing.lines_from_file(PARAGRAPH_PATH) paragraph_index = randrange(len(paragraphs)) return typing.choose(paragraphs, lambda x: True, paragraph_index)
from http import server, HTTPStatus from http.server import HTTPServer from random import randrange from urllib.error import URLError from ucb import main from urllib.request import Request, urlopen from urllib.parse import urlencode, unquote, parse_qs import typing PORT = 31415 DEFAULT_SERVER = 'https://cats.cs61a.org' PARAGRAPH_PATH = "./data/sample_paragraphs.txt" WORDS_LIST = typing.lines_from_file('data/words.txt') WORDS_SET = set(WORDS_LIST) LETTER_SETS = [(w, set(w)) for w in WORDS_LIST] LIMIT = 2 PATHS = {} def route(path): """Register a route handler.""" def wrap(f): PATHS[path] = f return f return wrap