[wip] do not use subroutes and HalfDomain.read_routes is a generator
This commit is contained in:
parent
910e1e1497
commit
ef4a4c2b98
|
@ -212,7 +212,7 @@ class HalfDomain(Starlette):
|
||||||
that decorates the endpoint function.
|
that decorates the endpoint function.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for subpath, params in HalfDomain.read_router(m_router).items():
|
for subpath, params in HalfDomain.read_router(m_router):
|
||||||
path.append(subpath)
|
path.append(subpath)
|
||||||
|
|
||||||
for verb in VERBS:
|
for verb in VERBS:
|
||||||
|
@ -265,40 +265,45 @@ class HalfDomain(Starlette):
|
||||||
m_path = None
|
m_path = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not hasattr(m_router, 'ROUTES'):
|
acls = getattr(m_router, 'ACLS', None)
|
||||||
routes = {'':{}}
|
routes = getattr(m_router, 'ROUTES', None)
|
||||||
acls = getattr(m_router, 'ACLS') if hasattr(m_router, 'ACLS') else None
|
|
||||||
|
|
||||||
if acls is not None:
|
if acls is not None:
|
||||||
for method in acls.keys():
|
for method in acls.keys():
|
||||||
if method not in VERBS:
|
if method not in VERBS:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
'This method is not handled: {}'.format(method))
|
'This method is not handled: {}'.format(method))
|
||||||
|
|
||||||
routes[''][method] = []
|
yield '', dict([(method, acls[method].copy())])
|
||||||
routes[''][method] = acls[method].copy()
|
|
||||||
|
|
||||||
routes['']['SUBROUTES'] = []
|
|
||||||
if hasattr(m_router, '__path__'):
|
|
||||||
""" Module is a package
|
|
||||||
"""
|
|
||||||
m_path = getattr(m_router, '__path__')
|
|
||||||
if isinstance(m_path, list) and len(m_path) == 1:
|
|
||||||
routes['']['SUBROUTES'] = [
|
|
||||||
elt.name
|
|
||||||
for elt in os.scandir(m_path[0])
|
|
||||||
if elt.is_dir()
|
|
||||||
]
|
|
||||||
else:
|
else:
|
||||||
routes = getattr(m_router, 'ROUTES')
|
for method in VERBS:
|
||||||
|
if not hasattr(m_router, method):
|
||||||
|
continue
|
||||||
|
|
||||||
try:
|
yield '', getattr(m_router, method)
|
||||||
ROUTER_SCHEMA.validate(routes)
|
|
||||||
except SchemaError as exc:
|
|
||||||
logger.error(routes)
|
|
||||||
raise exc
|
|
||||||
|
|
||||||
return routes
|
# routes['']['SUBROUTES'] = []
|
||||||
|
# if hasattr(m_router, '__path__'):
|
||||||
|
# """ Module is a package
|
||||||
|
# """
|
||||||
|
# m_path = getattr(m_router, '__path__')
|
||||||
|
# if isinstance(m_path, list) and len(m_path) == 1:
|
||||||
|
# routes['']['SUBROUTES'] = [
|
||||||
|
# elt.name
|
||||||
|
# for elt in os.scandir(m_path[0])
|
||||||
|
# if elt.is_dir()
|
||||||
|
# ]
|
||||||
|
|
||||||
|
# try:
|
||||||
|
# ROUTER_SCHEMA.validate(routes)
|
||||||
|
# except SchemaError as exc:
|
||||||
|
# logger.error(routes)
|
||||||
|
# raise exc
|
||||||
|
|
||||||
|
if routes is not None:
|
||||||
|
for key, value in routes.items():
|
||||||
|
yield key, value
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
# TODO: Proper exception handling
|
# TODO: Proper exception handling
|
||||||
raise exc
|
raise exc
|
||||||
|
|
Loading…
Reference in New Issue