comparison MoinMoin/config/multiconfig.py @ 3767:0b7f7b9226df

config: improve some lazy-loading code
author Johannes Berg <johannes AT sipsolutions DOT net>
date Sun, 22 Jun 2008 14:52:02 +0200
parents 6a618481be28
children c57d79281471
comparison
equal deleted inserted replaced
3766:6a618481be28 3767:0b7f7b9226df
367 if k in settings: 367 if k in settings:
368 continue 368 continue
369 self.computed_settings[k] = True 369 self.computed_settings[k] = True
370 370
371 371
372 _meta_dict = None
372 def load_meta_dict(self): 373 def load_meta_dict(self):
373 """ The meta_dict contains meta data about the wiki instance. """ 374 """ The meta_dict contains meta data about the wiki instance. """
374 if getattr(self, "_meta_dict", None) is None: 375 if self._meta_dict is None:
375 self._meta_dict = wikiutil.MetaDict(os.path.join(self.data_dir, 'meta'), self.cache_dir) 376 self._meta_dict = wikiutil.MetaDict(os.path.join(self.data_dir, 'meta'), self.cache_dir)
376 return self._meta_dict 377 return self._meta_dict
377 meta_dict = property(load_meta_dict) 378 meta_dict = property(load_meta_dict)
378 379
379 # lazily load iwid(_full) 380 # lazily load iwid(_full)
385 return property(getter) 386 return property(getter)
386 iwid = make_iwid_property("_iwid") 387 iwid = make_iwid_property("_iwid")
387 iwid_full = make_iwid_property("_iwid_full") 388 iwid_full = make_iwid_property("_iwid_full")
388 389
389 # lazily create a list of event handlers 390 # lazily create a list of event handlers
391 _event_handlers = None
390 def make_event_handlers_prop(): 392 def make_event_handlers_prop():
391 def getter(self): 393 def getter(self):
392 if getattr(self, "_event_handlers", None) is None: 394 if self._event_handlers is None:
393 self._event_handlers = events.get_handlers(self) 395 self._event_handlers = events.get_handlers(self)
394 return getattr(self, "_event_handlers") 396 return self._event_handlers
395 397
396 def setter(self, new_handlers): 398 def setter(self, new_handlers):
397 self._event_handlers = new_handlers 399 self._event_handlers = new_handlers
398 400
399 return property(getter, setter) 401 return property(getter, setter)