Compare commits

...

1 Commits

1 changed files with 34 additions and 29 deletions

View File

@ -212,7 +212,7 @@ class HalfDomain(Starlette):
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)
for verb in VERBS:
@ -265,40 +265,45 @@ class HalfDomain(Starlette):
m_path = None
try:
if not hasattr(m_router, 'ROUTES'):
routes = {'':{}}
acls = getattr(m_router, 'ACLS') if hasattr(m_router, 'ACLS') else None
acls = getattr(m_router, 'ACLS', None)
routes = getattr(m_router, 'ROUTES', None)
if acls is not None:
for method in acls.keys():
if method not in VERBS:
raise Exception(
'This method is not handled: {}'.format(method))
if acls is not None:
for method in acls.keys():
if method not in VERBS:
raise Exception(
'This method is not handled: {}'.format(method))
routes[''][method] = []
routes[''][method] = acls[method].copy()
yield '', dict([(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:
routes = getattr(m_router, 'ROUTES')
for method in VERBS:
if not hasattr(m_router, method):
continue
try:
ROUTER_SCHEMA.validate(routes)
except SchemaError as exc:
logger.error(routes)
raise exc
yield '', getattr(m_router, method)
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:
# TODO: Proper exception handling
raise exc