27 lines
901 B
Python
27 lines
901 B
Python
# TODO(Ed): Do we need these in a speparate module?
|
|
|
|
def _get_app_attr(app: Any, name: str, default: Any = None) -> Any:
|
|
"""Retrieves an attribute from the App or its Controller."""
|
|
if hasattr(app, name):
|
|
val = getattr(app, name)
|
|
return val
|
|
if hasattr(app, 'controller') and hasattr(app.controller, name):
|
|
val = getattr(app.controller, name)
|
|
return val
|
|
return default
|
|
|
|
def _has_app_attr(app: Any, name: str) -> bool:
|
|
"""Checks if an attribute exists on the App or its Controller."""
|
|
if hasattr(app, name): return True
|
|
if hasattr(app, 'controller') and hasattr(app.controller, name): return True
|
|
return False
|
|
|
|
def _set_app_attr(app: Any, name: str, value: Any) -> None:
|
|
"""Sets an attribute on the App or its Controller."""
|
|
if hasattr(app, name):
|
|
setattr(app, name, value)
|
|
elif hasattr(app, 'controller'):
|
|
setattr(app.controller, name, value)
|
|
else:
|
|
setattr(app, name, value)
|
|
|