| | 155 | class ActiveSettings(object): |
| | 156 | """ |
| | 157 | Serves ActiveSettings. Falls back to LazySettings() for everything else. |
| | 158 | """ |
| | 159 | def __init__(self): |
| | 160 | self.lazy_settings = LAZY_SETTINGS |
| | 161 | def __getattr__(self, name): |
| | 162 | active_settings = getattr(self.lazy_settings, 'ACTIVE_SETTINGS') |
| | 163 | if name in active_settings: |
| | 164 | return importlib.import_module(active_settings[name]) |
| | 165 | else: |
| | 166 | return getattr(self.lazy_settings, name) |
| | 167 | def __dir__(self): |
| | 168 | return self.__dict__.keys() + dir(self.lazy_settings) |
| | 169 | |
| | 170 | # For Python < 2.6: |
| | 171 | __members__ = property(lambda self: self.__dir__()) |
| | 172 | |
| | 173 | # Just to make sure that the overhead of ActiveSettings is only introduced if it is configured. |
| | 174 | if LAZY_SETTINGS.ACTIVE_SETTINGS: |
| | 175 | settings = ActiveSettings() |
| | 176 | else: |
| | 177 | settings = LAZY_SETTINGS |
| | 178 | |