From 53395a9dd29c3dfdf3def032e85d8c3a90e1bf22 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sat, 11 May 2013 16:22:05 +0200 Subject: [PATCH] Added a lazy-loading dict of known, named libraries. --- manga/lib.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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() -- 2.11.0