From: Fredrik Tolf Date: Sat, 11 May 2013 14:22:05 +0000 (+0200) Subject: Added a lazy-loading dict of known, named libraries. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=53395a9dd29c3dfdf3def032e85d8c3a90e1bf22;p=automanga.git Added a lazy-loading dict of known, named libraries. --- diff --git a/manga/lib.py b/manga/lib.py index ffea7a3..2a11cb1 100644 --- a/manga/lib.py +++ b/manga/lib.py @@ -171,3 +171,18 @@ class cursor(object): def __iter__(self): return self + +def _lazymod(name): + return __import__(name, fromlist=["dummy"]) +class _lazydict(object): + def __init__(self): + self.bk = {} + def __setitem__(self, key, val): + self.bk[key] = "u", val + def __getitem__(self, key): + st, v = self.bk[key] + if st == "u": + v = self.bk[key] = v() + return v +libraries = _lazydict() +libraries["mf"] = lambda: _lazymod("manga.mangafox").library()