22 lines
808 B
Python
22 lines
808 B
Python
from pyapp.utils.log import Log
|
|
|
|
application_class = {}
|
|
def PyApplication(arg=None):
|
|
if callable(arg):
|
|
cls = arg
|
|
if "default" in application_class:
|
|
Log.error("Multiple classes annotated with default @PyApplication, require a 'name' parameter.", True)
|
|
application_class["default"] = cls
|
|
return cls
|
|
|
|
else:
|
|
name = arg
|
|
def decorator(cls):
|
|
if name is None:
|
|
raise Log.error("The 'name' parameter is required when using @PyApplication with arguments.", True)
|
|
if name in application_class:
|
|
raise Log.error(f"Multiple classes annotated with @PyApplication with the same name '{name}' found.", True)
|
|
application_class[name] = cls
|
|
return cls
|
|
return decorator
|