from twisted.web import resource from hatena import NotFound, as_text from reximemo import search_keyboard_response class PyResource(resource.Resource): isLeaf = False def getChild(self, name, request): scope = as_text(name) if scope in {"flipnotes.kbd", "creators.kbd"}: return SearchKeyboard(scope.split(".", 1)[0]) return NotFound class SearchKeyboard(resource.Resource): isLeaf = True def __init__(self, scope): super().__init__() self.scope = scope def render_POST(self, request): return search_keyboard_response(request, self.scope) def render_GET(self, request): request.setResponseCode(405) return b""