Commits

bbangert  committed e7f6ba1

[svn] Changed deprecated style to register vars in proper location, only throw deprecated warnings on middleware init from old locations.

  • Participants
  • Parent commits 72cdb56

Comments (0)

Files changed (3)

File beaker/cache.py

+import warnings
 import beaker.container as container
 from beaker.exceptions import InvalidCacheBackendError
 from beaker.util import coerce_cache_params
 import beaker.util as util
 
-import warnings
-warnings.warn('CacheMiddleware is moving to beaker.middleware in '
-              '0.8', DeprecationWarning, 2)
+try:
+    from paste.registry import StackedObjectProxy
+    beaker_cache = StackedObjectProxy(name="Cache Manager")
+except:
+    beaker_cache = None
+
 clsmap = {
           'memory':container.MemoryContainer,
           'dbm':container.DBMContainer,
         return self.caches.setdefault(name + str(kw), Cache(name, **kw))
 
 class CacheMiddleware(object):
+    deprecated = True
+    cache = beaker_cache
+    
     def __init__(self, app, config=None, environ_key='beaker.cache', **kwargs):
         """Initialize the Cache Middleware
         
             All keyword arguments are assumed to be cache settings and will
             override any settings found in ``config``
         """
+        if self.deprecated:
+            warnings.warn('CacheMiddleware is moving to beaker.middleware in '
+                          '0.8', DeprecationWarning, 2)
+        
         self.app = app
         config = config or {}
 
     
     def __call__(self, environ, start_response):
         if environ.get('paste.registry'):
-            environ['paste.registry'].register(beaker_cache, self.cache_manager)
+            environ['paste.registry'].register(self.cache, self.cache_manager)
         environ[self.environ_key] = self.cache_manager
         return self.app(environ, start_response)

File beaker/middleware.py

     beaker_session = StackedObjectProxy(name="Beaker Session")
     beaker_cache = StackedObjectProxy(name="Cache Manager")
 except:
-    pass
+    beaker_cache = None
+    beaker_session = None
 
+from beaker.cache import CacheMiddleware as DeprecatedCacheMiddleware
 from beaker.converters import asbool
+from beaker.session import SessionMiddleware as DeprecatedSessionMiddleware
 
-import warnings
-warnings.simplefilter('ignore', DeprecationWarning)
-from beaker.cache import CacheMiddleware
-from beaker.session import SessionMiddleware
-warnings.simplefilter('default', DeprecationWarning)
+class CacheMiddleware(DeprecatedCacheMiddleware):
+    deprecated = False
+    cache = beaker_cache
+
+class SessionMiddleware(DeprecatedSessionMiddleware):
+    deprecated = False
+    session = beaker_session
 
 def session_filter_factory(global_conf, **kwargs):
     def filter(app):

File beaker/session.py

 import time
 import UserDict
 import warnings
-warnings.warn('SessionMiddleware is moving to beaker.middleware in '
-              '0.8', DeprecationWarning, 2)
+
+try:
+    from paste.registry import StackedObjectProxy
+    beaker_session = StackedObjectProxy(name="Beaker Session")
+except:
+    beaker_session = None
 
 from beaker.container import namespace_registry
 from beaker.util import coerce_session_params
         return self._session().has_key(key)
 
 class SessionMiddleware(object):
+    deprecated = True
+    session = beaker_session
+    
     def __init__(self, wrap_app, config=None, environ_key='beaker.session', **kwargs):
         """Initialize the Session Middleware
         
             All keyword arguments are assumed to be cache settings and will
             override any settings found in ``config``
         """
+        if self.deprecated:
+            warnings.warn('SessionMiddleware is moving to beaker.middleware in '
+              '0.8', DeprecationWarning, 2)
+        
         config = config or {}
         
         # Load up the default params
     def __call__(self, environ, start_response):
         session = SessionObject(environ, **self.options)
         if environ.get('paste.registry'):
-            environ['paste.registry'].register(beaker_session, session)
+            environ['paste.registry'].register(self.session, session)
         environ[self.environ_key] = session
         
         def session_start_response(status, headers, exc_info = None):