-
Notifications
You must be signed in to change notification settings - Fork 593
/
Copy path__init__.py
37 lines (28 loc) · 1.1 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# Author: Binux<[email protected]>
# http://binux.me
# Created on 2012-12-15 16:15:50
import importlib
import os
import pkgutil
from . import base
def load_modules():
handlers: list[tuple[str, base.BaseHandler]] = []
ui_modules: dict[str, base.BaseUIModule] = {}
ui_methods: dict[str, base.BaseWebSocketHandler] = {}
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.BaseWebSocketHandler]
handlers, ui_modules, ui_methods = load_modules()