Author: gjm
Date: Mon Sep 30 19:38:07 2013
New Revision: 1527743

URL: http://svn.apache.org/r1527743
Log:
adding a decorator to allow ProductEnvironment creation using a 
ProductEnvironment in place of it's parent - towards #676

Modified:
    bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py

Modified: bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py?rev=1527743&r1=1527742&r2=1527743&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py (original)
+++ bloodhound/trunk/bloodhound_multiproduct/multiproduct/env.py Mon Sep 30 
19:38:07 2013
@@ -362,6 +362,15 @@ class ProductEnvironment(Component, Comp
     
     class __metaclass__(ComponentMeta):
 
+        def select_global_env(f):
+            """Replaces env with env.parent where appropriate"""
+            # Keep the signature of __call__ method
+            def __call__(self, env, *args, **kwargs):
+                g_env = env.parent if isinstance(env,
+                                                 ProductEnvironment) else env
+                return f(self, g_env, *args, **kwargs)
+            return __call__
+
         def product_env_keymap(args, kwds, kwd_mark):
             # Remove meta-reference to self (i.e. product env class)
             args = args[1:]
@@ -377,14 +386,15 @@ class ProductEnvironment(Component, Comp
                     kwds['product'] = product.prefix
             return default_keymap(args, kwds, kwd_mark)
 
+        @select_global_env
         @lru_cache(maxsize=100, keymap=product_env_keymap)
         def __call__(self, *args, **kwargs):
-            """Return an existing instance of there is a hit 
+            """Return an existing instance if there is a hit
             in the global LRU cache, otherwise create a new instance.
             """
             return ComponentMeta.__call__(self, *args, **kwargs)
 
-        del product_env_keymap
+        del product_env_keymap, select_global_env
 
     implements(trac.env.ISystemInfoProvider, IPermissionRequestor)
 


Reply via email to