Skip to content

API 的插件框架 #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
47 changes: 26 additions & 21 deletions web/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@
# http://binux.me
# Created on 2012-12-15 16:15:50

import importlib
import os
import sys
import pkgutil

sys.path.append(os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))
from . import base

handlers = []
ui_modules = {}
ui_methods = {}
modules = []
for file in os.listdir(os.path.dirname(__file__)):
if not file.endswith(".py"):
continue
if file == "__init__.py":
continue
modules.append(file[:-3])

for module in modules:
module = __import__('%s.%s' % (__package__, module), fromlist = ["handlers"])
if hasattr(module, "handlers"):
handlers.extend(module.handlers)
if hasattr(module, "ui_modules"):
ui_modules.update(module.ui_modules)
if hasattr(module, "ui_methods"):
ui_methods.update(module.ui_methods)

def load_modules():
handlers: list[tuple[str, base.BaseHandler]] = []
ui_modules: dict[str, base.BaseUIModule] = {}
ui_methods: dict[str, base.BaseWebSocket] = {}

path = os.path.join(os.path.dirname(__file__), "")
for finder, name, ispkg in pkgutil.iter_modules([path]):
module = importlib.import_module("." + name, __name__)
if hasattr(module, "handlers"):
handlers.extend(module.handlers)
if hasattr(module, "ui_modules"):
ui_modules.update(module.ui_modules)
if hasattr(module, "ui_methods"):
ui_methods.update(module.ui_methods)

return handlers, ui_modules, ui_methods


handlers: list[tuple[str, base.BaseHandler]]
ui_modules: dict[str, base.BaseUIModule]
ui_methods: dict[str, base.BaseWebSocket]

handlers, ui_modules, ui_methods = load_modules()
14 changes: 11 additions & 3 deletions web/handlers/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
# http://binux.me
# Created on 2014-08-08 21:06:02

from . import api
from .api import BodyArgument, MultiArgument
from .base import *


class AboutHandler(BaseHandler):
@tornado.web.addslash
async def get(self):
await self.render('about.html')
await self.render(
"about.html",
apis=api.apis,
ismulti=lambda x: isinstance(x, MultiArgument),
isbody=lambda x: isinstance(x, BodyArgument),
)
return


handlers = [
('/about/?', AboutHandler),
]
("/about/?", AboutHandler),
]
Loading