From 02c9e2b5179348dfa83899d094c226e7aae1cc7d Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 18 Jun 2009 08:43:03 +0000 Subject: - Cache the absolute path in the caller's package globals within ``repoze.bfg.path`` to get rid of repeated (expensive) calls to os.path.abspath. --- CHANGES.txt | 5 ++++- repoze/bfg/path.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3b2772523..c54385b3c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,10 @@ Next release Features -------- +- Cache the absolute path in the caller's package globals within + ``repoze.bfg.path`` to get rid of repeated (expensive) calls to + os.path.abspath. + - Add ``reissue_time`` and ``timeout`` parameters to ``repoze.bfg.authentication.AuthTktAuthenticationPolicy`` constructor. If these are passed, cookies will be reset every so @@ -109,7 +113,6 @@ Documentation - Updated Routes bfgwiki2 tutorial to reflect the fact that context factories are now no longer used. - 0.9.1 (2009-06-02) ================== diff --git a/repoze/bfg/path.py b/repoze/bfg/path.py index fcd317fba..c3d914208 100644 --- a/repoze/bfg/path.py +++ b/repoze/bfg/path.py @@ -4,9 +4,16 @@ import sys def caller_path(path, level=2): if not os.path.isabs(path): package_globals = sys._getframe(level).f_globals - package_name = package_globals['__name__'] - package = sys.modules[package_name] - prefix = package_path(package) + if '__bfg_abspath__' not in package_globals: + # this is actually kinda expensive so we memoize the result + package_name = package_globals['__name__'] + package = sys.modules[package_name] + prefix = package_path(package) + try: + package_globals['__bfg_abspath__'] = prefix + except: + pass + prefix = package_globals['__bfg_abspath__'] path = os.path.join(prefix, path) return path -- cgit v1.2.3