From 728e36118a6d51647e85e92913fc2ed315dc4404 Mon Sep 17 00:00:00 2001 From: vky Date: Fri, 28 Jan 2022 17:58:25 +0100 Subject: [PATCH] added getters and setters --- src/bootstraparse/modules/environment.py | 31 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/bootstraparse/modules/environment.py b/src/bootstraparse/modules/environment.py index 3672044..554dee3 100644 --- a/src/bootstraparse/modules/environment.py +++ b/src/bootstraparse/modules/environment.py @@ -1,6 +1,9 @@ # Module for containing super important variables +import rich + + class environment(): """ Object containing all the important variables, @@ -10,7 +13,7 @@ class environment(): def __init__(self): # mandatoryParameters - self.mParams = { + self._mParams = { 'config': None, 'context_mngr': None, 'export_mngr': None, @@ -20,15 +23,35 @@ class environment(): } # secondaryParameters - self.sParams = { + self._sParams = { } # Set all parameters to uninitialised - self.wasInitialised = {p: False for p in self.mParams} + self._wasInitialised = {p: False for p in self._mParams} def integritycheck(self): - for value in self.wasInitialised.values(): + for value in self._wasInitialised.values(): if value is False: return False return True + + def __getattr__(self, attribute): + if attribute[0] == "_": + super().__getattr__(attribute) + elif attribute in self._mParams: + return self._mParams[attribute] + elif attribute in self._sParams: + return self._sParams[attribute] + else: + raise KeyError(attribute) + + def __setattr__ (self, attribute, value): + if attribute[0] == "_": + super().__setattr__(attribute, value) + elif attribute in self._mParams: + self._mParams[attribute] = value + elif attribute in self._sParams: + self._sParams[attribute] = value + else: + raise KeyError(attribute) #could also add attribute as a new entry