Commits

Lynn Rees committed e05fb6f Merge

- merge

  • Participants
  • Parent commits 01d4cc3, 8b6affe
  • Branches wsgistate

Comments (0)

Files changed (10)

 Changes between 0.4 and 0.4.1
 
 - only caches explicitly declared HTTP methods (Roberto De Alemeida)
-- non-destructively consumes 'wsgi.input' (Roberto De Alemeida)
+- non-destructively consumes 'wsgi.input' (Roberto De Alemeida)
+
+Changes between 0.4.1 and 0.4.2
+
+- update to work with SQLAlchemy 0.4.x
+- support for Paste Deploy
-# Copyright (c) 2006 L. C. Rees.  All rights reserved.
+# Copyright (c) 2006-2007 L. C. Rees.  All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are met:
 
 try:
     from setuptools import setup
-except:
+except ImportError:
     from distutils.core import setup
 
-setup(name='wsgistate',
-      version='0.4.1',
-      description='''WSGI session and caching middleware.''',
-      long_description='''Session (flup-compatible), caching, memoizing, and HTTP cache control
+setup(
+    name='wsgistate',
+    version='0.4.2',
+    description='''WSGI session and caching middleware.''',
+    long_description='''Session (flup-compatible), caching, memoizing, and HTTP cache control
 middleware for WSGI. Supports memory, filesystem, database, and memcached based backends.
 
 # Simple memoization example:
     from wsgiref.simple_server import make_server
     http = make_server('', 8080, app)
     http.serve_forever()''',
-      author='L. C. Rees',
-      author_email='lcrees@gmail.com',
-      license='BSD',
-      packages = ['wsgistate'],
-      test_suite='wsgistate.tests',
-      zip_safe = True,
-      keywords='WSGI session caching persistence memoizing HTTP Web',
-      classifiers=['Development Status :: 4 - Beta',
-                    'Environment :: Web Environment',
-                    'License :: OSI Approved :: BSD License',
-                    'Natural Language :: English',
-                    'Operating System :: OS Independent',
-                    'Programming Language :: Python',
-                    'Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware'],
-      install_requires = ['SQLAlchemy'],)
+    author='L. C. Rees',
+    author_email='lcrees@gmail.com',
+    url='http://pypi.python.org/pypi/wsgistate/',
+    license='BSD',
+    packages = ['wsgistate', 'wsgistate.tests'],
+    test_suite='wsgistate.tests',
+    zip_safe = False,
+    keywords='WSGI session caching persistence memoizing HTTP Web',
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Environment :: Web Environment',
+        'License :: OSI Approved :: BSD License',
+        'Natural Language :: English',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware',
+    ],
+    install_requires = ['SQLAlchemy>0.3', 'python-memcached'],
+    entry_points='''
+    [paste.filter_factory]
+    file_memo=wsgistate.file:filememo_deploy
+    firebird_memo=wsgistate.db:dbmemo_deploy
+    memcache_memo=wsgistate.memcached:mcmemo_deploy
+    memory_memo=wsgistate.memory:memorymemo_deploy
+    mssql_memo=wsgistate.db:dbmemo_deploy
+    mysql_memo=wsgistate.db:dbmemo_deploy
+    oracle_memo=wsgistate.db:dbmemo_deploy
+    postgres_memo=wsgistate.db:dbmemo_deploy
+    simple_memo=wsgistate.simple:simplememo_deploy
+    sqlite_memo=wsgistate.db:dbmemo_deploy
+    file_session=wsgistate.file:filesess_deploy
+    firebird_session=wsgistate.db:dbsess_deploy
+    memcache_session=wsgistate.memcached:mcsess_deploy
+    memory_session=wsgistate.memory:memorysess_deploy
+    mssql_session=wsgistate.db:dbsess_deploy
+    mysql_session=wsgistate.db:dbsess_deploy
+    oracle_session=wsgistate.db:dbsess_deploy
+    postgres_session=wsgistate.db:dbsess_deploy
+    simple_session=wsgistate.simple:simplesess_deploy
+    sqlite_session=wsgistate.db:dbsess_deploy
+    file_urlsess=wsgistate.file:fileurlsess_deploy
+    firebird_urlsess=wsgistate.db:dburlsess_deploy
+    memcache_urlsess=wsgistate.memcached:mcurlsess_deploy
+    memory_urlsess=wsgistate.memory:memoryurlsess_deploy
+    mssql_urlsess=wsgistate.db:dburlsess_deploy
+    mysql_urlsess=wsgistate.db:dburlsess_deploy
+    oracle_urlsess=wsgistate.db:dburlsess_deploy
+    postgres_urlsess=wsgistate.db:dburlsess_deploy
+    simple_urlsess=wsgistate.simple:simpleurlsess_deploy
+    sqlite_urlsess=wsgistate.db:dburlsess_deploy
+    '''
+)

File wsgistate/cache.py

     'nocache', 'nostore', 'notransform', 'revalidate', 'proxyrevalidate',
     'maxage', 'smaxage', 'vary', 'modified']
 
+def memoize(cache, **kw):
+    '''Decorator for caching.'''
+    def decorator(application):
+        return WsgiMemoize(application, cache, **kw)
+    return decorator
+
 def getinput(environ):
     '''Non-destructively retrieves wsgi.input value.'''
     wsginput = environ['wsgi.input']
     return {'Cache-Control':value % seconds, 'Date':rfc822.formatdate(now),
         'Expires':rfc822.formatdate(now + seconds)}
 
-def memoize(cache, **kw):
-    '''Decorator for caching.'''
-    def decorator(application):
-        return WsgiMemoize(application, cache, **kw)
-    return decorator
-
 def control(application, value):
     '''Generic setter for 'Cache-Control' headers.
 
             else:
                 win = getinput(environ)
                 if win != '': key.append(win)
-        return ''.join(key)
+        return ''.join(key)

File wsgistate/db.py

 # Redistribution and use in source and binary forms, with or without modification,
 # are permitted provided that the following conditions are met:
 #
-#    1. Redistributions of source code must retain the above copyright notice, 
+#    1. Redistributions of source code must retain the above copyright notice,
 #       this list of conditions and the following disclaimer.
-#    
-#    2. Redistributions in binary form must reproduce the above copyright 
+#
+#    2. Redistributions in binary form must reproduce the above copyright
 #       notice, this list of conditions and the following disclaimer in the
 #       documentation and/or other materials provided with the distribution.
 #
 '''Database cache backend.'''
 
 import time
+from random import choice
 from datetime import datetime
+
+from sqlalchemy import (
+        Table, Column, String, Binary, DateTime,
+        Integer, PickleType, bindparam, select, update,
+        delete, insert,
+    )
 try:
-    from sqlalchemy import *
+    from sqlalchemy import BoundMetaData
 except ImportError:
-    raise ImportError('DbCache module requires the SQLAlchemy package ' \
-        'from http://www.sqlalchemy.org/')
+    from sqlalchemy import MetaData as BoundMetaData
+
 from wsgistate import BaseCache
 from wsgistate.cache import WsgiMemoize
 from wsgistate.session import CookieSession, URLSession, SessionCache
 
 __all__ = ['DbCache', 'memoize', 'session', 'urlsession']
 
+def dbmemo_deploy(global_conf, **kw):
+    '''Paste Deploy loader for caching.'''
+    def decorator(application):
+        _db_memo_cache = DbCache(kw.get('cache'), **kw)
+        return WsgiMemoize(application, _db_memo_cache, **kw)
+    return decorator
+
+def dbsession_deploy(global_conf, **kw):
+    '''Paste Deploy loader for sessions.'''
+    def decorator(application):
+        _db_base_cache = DbCache(kw.get('cache'), **kw)
+        _db_session_cache = SessionCache(_db_base_cache, **kw)
+        return CookieSession(application, _db_session_cache, **kw)
+    return decorator
+
+def dburlsess_deploy(global_conf, **kw):
+    '''Paste Deploy loader for URL encoded sessions.
+
+    @param initstr Database initialization string
+    '''
+    def decorator(application):
+        _db_ubase_cache = DbCache(kw.get('cache'), **kw)
+        _db_url_cache = SessionCache(_db_ubase_cache, **kw)
+        return URLSession(application, _db_url_cache, **kw)
+    return decorator
 
 def memoize(initstr, **kw):
     '''Decorator for caching.
     return decorator
 
 
-class DbCache(BaseCache):     
+class DbCache(BaseCache):
 
     '''Database cache backend.'''
 
         # Bind metadata
         self._metadata = BoundMetaData(a[0])
         # Make cache
-        self._cache = Table(tablename, self._metadata,
-            Column('id', Integer, primary_key=True, nullable=False, unique=True),
+        self._cache = Table(
+            tablename, self._metadata,
+            Column(
+                'id', Integer, primary_key=True, nullable=False, unique=True
+            ),
             Column('key', String(60), nullable=False),
             Column('value', PickleType, nullable=False),
-            Column('expires', DateTime, nullable=False))
+            Column('expires', DateTime, nullable=False)
+        )
         # Create cache if it does not exist
         if not self._cache.exists(): self._cache.create()
         # Maximum number of entries to cull per call if cache is full
-        self._maxcull = kw.get('maxcull', 10)                
+        self._maxcull = kw.get('maxcull', 10)
         max_entries = kw.get('max_entries', 300)
         try:
             self._max_entries = int(max_entries)
     def __len__(self):
         return self._cache.count().execute().fetchone()[0]
 
-    def get(self, k, default=None):
+    def get(self, key, default=None):
         '''Fetch a given key from the cache.  If the key does not exist, return
         default, which itself defaults to None.
 
         @param key Keyword of item in cache.
         @param default Default value (default: None)
         '''
-        row = self._cache.select().execute(key=k).fetchone()
-        if row is None: return default
+        row = select(
+            [self._cache.c.value, self._cache.c.expires],
+            self._cache.c.key==key
+        ).execute().fetchone()
+        if row is None:
+            return default
         if row.expires < datetime.now().replace(microsecond=0):
-            self.delete(k)
+            self.delete(key)
             return default
         return row.value
 
-    def set(self, k, v):
+    def set(self, key, value):
         '''Set a value in the cache.
 
         @param key Keyword of item in cache.
-        @param value Value to be inserted in cache.      
+        @param value Value to be inserted in cache.
         '''
         if len(self) > self._max_entries: self._cull()
         timeout, cache = self.timeout, self._cache
         # Get expiration time
-        exp = datetime.fromtimestamp(time.time() + timeout).replace(microsecond=0)        
+        expires = datetime.fromtimestamp(
+            time.time() + timeout
+        ).replace(microsecond=0)
         #try:
         # Update database if key already present
-        if k in self:
-            cache.update(cache.c.key==k).execute(value=v, expires=exp)
+        if key in self:
+            update(
+                cache,
+                cache.c.key==key,
+                dict(value=value, expires=expires),
+            ).execute()
         # Insert new key if key not present
-        else:            
-            cache.insert().execute(key=k, value=v, expires=exp)
+        else:
+            insert(cache, dict(key=key, value=value, expires=expires)).execute()
         # To be threadsafe, updates/inserts are allowed to fail silently
         #except: pass
-       
+
     def delete(self, k):
         '''Delete a key from the cache, failing silently.
 
         @param key Keyword of item in cache.
         '''
-        self._cache.delete(self._cache.c.key==k).execute()
+        delete(self._cache, self._cache.c.key==k).execute()
 
     def _cull(self):
-        '''Remove items in cache to make more room.'''        
+        '''Remove items in cache to make more room.'''
         cache, maxcull = self._cache, self._maxcull
         # Remove items that have timed out
         now = datetime.now().replace(microsecond=0)
-        cache.delete(cache.c.expires < now).execute()
+        delete(cache, cache.c.expires < now).execute()
         # Remove any items over the maximum allowed number in the cache
         if len(self) >= self._max_entries:
             # Upper limit for key query
             ul = maxcull * 2
             # Get list of keys
-            keys = [i[0] for i in select([cache.c.key], limit=ul).execute().fetchall()]
+            keys = [
+                i[0] for i in select(
+                    [cache.c.key], limit=ul
+                ).execute().fetchall()
+            ]
             # Get some keys at random
-            delkeys = list(random.choice(keys) for i in range(maxcull))
+            delkeys = list(choice(keys) for i in xrange(maxcull))
             # Delete keys
             fkeys = tuple({'key':k} for k in delkeys)
-            cache.delete(cache.c.key.in_(bindparam('key'))).execute(*fkeys)
+            delete(cache, cache.c.key.in_(bindparam('key'))).execute(*fkeys)

File wsgistate/file.py

 # Redistribution and use in source and binary forms, with or without modification,
 # are permitted provided that the following conditions are met:
 #
-#    1. Redistributions of source code must retain the above copyright notice, 
+#    1. Redistributions of source code must retain the above copyright notice,
 #       this list of conditions and the following disclaimer.
-#    
-#    2. Redistributions in binary form must reproduce the above copyright 
+#
+#    2. Redistributions in binary form must reproduce the above copyright
 #       notice, this list of conditions and the following disclaimer in the
 #       documentation and/or other materials provided with the distribution.
 #
     import cPickle as pickle
 except ImportError:
     import pickle
+
 from wsgistate.simple import SimpleCache
 from wsgistate.cache import WsgiMemoize
 from wsgistate.session import CookieSession, URLSession, SessionCache
 
 __all__ = ['FileCache', 'memoize', 'session', 'urlsession']
 
+def filememo_deploy(global_conf, **kw):
+    '''Paste Deploy loader for caching.'''
+    def decorator(application):
+        _file_memo_cache = FileCache(kw.get('cache'), **kw)
+        return WsgiMemoize(application, _file_memo_cache, **kw)
+    return decorator
+
+def filesess_deploy(global_conf, **kw):
+    '''Paste Deploy loader for sessions.'''
+    def decorator(application):
+        _file_base_cache = FileCache(kw.get('cache'), **kw)
+        _file_session_cache = SessionCache(_file_base_cache, **kw)
+        return CookieSession(application, _file_session_cache, **kw)
+    return decorator
+
+def fileurlsess_deploy(global_conf, **kw):
+    '''Paste Deploy loader for URL encoded sessions.
+
+    @param initstr Database initialization string
+    '''
+    def decorator(application):
+        _file_ubase_cache = FileCache(kw.get('cache'), **kw)
+        _file_url_cache = SessionCache(_file_ubase_cache, **kw)
+        return URLSession(application, _file_url_cache, **kw)
+    return decorator
 
 def memoize(path, **kw):
     '''Decorator for caching.
 
 class FileCache(SimpleCache):
 
-    '''File-based cache backend'''    
-    
+    '''File-based cache backend'''
+
     def __init__(self, *a, **kw):
         super(FileCache, self).__init__(*a, **kw)
         # Create directory
         @param default Default value (default: None)
         '''
         try:
-            exp, value = pickle.load(open(self._key_to_file(key), 'rb')) 
+            exp, value = pickle.load(open(self._key_to_file(key), 'rb'))
             # Remove item if time has expired.
             if exp < time.time():
                 self.delete(key)
         '''Set a value in the cache.
 
         @param key Keyword of item in cache.
-        @param value Value to be inserted in cache.        
-        '''        
+        @param value Value to be inserted in cache.
+        '''
         if len(self.keys()) > self._max_entries: self._cull()
         try:
             fname = self._key_to_file(key)
     def keys(self):
         '''Returns a list of keys in the cache.'''
         return os.listdir(self._dir)
-    
+
     def _createdir(self):
         '''Creates the cache directory.'''
         try:
 
     def _key_to_file(self, key):
         '''Gives the filesystem path for a key.'''
-        return os.path.join(self._dir, urllib.quote_plus(key))
+        return os.path.join(self._dir, urllib.quote_plus(key))

File wsgistate/memcached.py

 
     def _cull(self):
         '''Stub.'''
-        pass
+        pass

File wsgistate/memory.py

 # Redistribution and use in source and binary forms, with or without modification,
 # are permitted provided that the following conditions are met:
 #
-#    1. Redistributions of source code must retain the above copyright notice, 
+#    1. Redistributions of source code must retain the above copyright notice,
 #       this list of conditions and the following disclaimer.
-#    
-#    2. Redistributions in binary form must reproduce the above copyright 
+#
+#    2. Redistributions in binary form must reproduce the above copyright
 #       notice, this list of conditions and the following disclaimer in the
 #       documentation and/or other materials provided with the distribution.
 #
     import threading
 except ImportError:
     import dummy_threading as threading
+
 from wsgistate import synchronized
 from wsgistate.simple import SimpleCache
 from wsgistate.cache import WsgiMemoize
 
 __all__ = ['MemoryCache', 'memoize', 'session', 'urlsession']
 
+def memorymemo_deploy(global_conf, **kw):
+    '''Paste Deploy loader for caching.'''
+    def decorator(application):
+        _memory_memo_cache = MemoryCache(kw.get('cache'), **kw)
+        return WsgiMemoize(application, _memory_memo_cache, **kw)
+    return decorator
+
+def memorysess_deploy(global_conf, **kw):
+    '''Paste Deploy loader for sessions.'''
+    def decorator(application):
+        _memory_base_cache = MemoryCache(kw.get('cache'), **kw)
+        _memory_session_cache = SessionCache(_memory_base_cache, **kw)
+        return CookieSession(application, _memory_session_cache, **kw)
+    return decorator
+
+def memoryurlsess_deploy(global_conf, **kw):
+    '''Paste Deploy loader for URL encoded sessions.
+
+    @param initstr Database initialization string
+    '''
+    def decorator(application):
+        _memory_ubase_cache = MemoryCache(kw.get('cache'), **kw)
+        _memory_url_cache = SessionCache(_memory_ubase_cache, **kw)
+        return URLSession(application, _memory_url_cache, **kw)
+    return decorator
+
 def memoize(**kw):
     '''Decorator for caching.'''
     def decorator(application):
 
 class MemoryCache(SimpleCache):
 
-    '''Thread-safe in-memory cache backend.'''    
+    '''Thread-safe in-memory cache backend.'''
 
     def __init__(self, *a, **kw):
         super(MemoryCache, self).__init__(*a, **kw)
         self._lock = threading.Condition()
-        
-    @synchronized        
+
+    @synchronized
     def get(self, key, default=None):
         '''Fetch a given key from the cache. If the key does not exist, return
         default, which itself defaults to None.
 
     @synchronized
     def set(self, key, value):
-        '''Set a value in the cache.  
+        '''Set a value in the cache.
 
         @param key Keyword of item in cache.
-        @param value Value to be inserted in cache.        
+        @param value Value to be inserted in cache.
         '''
         super(MemoryCache, self).set(key, value)
 
 
         @param key Keyword of item in cache.
         '''
-        super(MemoryCache, self).delete(key)
+        super(MemoryCache, self).delete(key)

File wsgistate/session.py

     import threading
 except ImportError:
     import dummy_threading as threading
+
 from wsgistate import synchronized
 
 __all__ = ['SessionCache', 'SessionManager', 'CookieSession', 'URLSession',
 def _shutdown(ref):
     cache = ref()
     if cache is not None: cache.shutdown()
-    
+
 def session(cache, **kw):
     '''Decorator for sessions.'''
     def decorator(application):
 
 
 class SessionCache(object):
-    
+
     '''Base class for session cache. You first acquire a session by
     calling create() or checkout(). After using the session, you must call
     checkin(). You must not keep references to sessions outside of a check
     @synchronized
     def create(self):
         '''Create a new session with a unique identifier.
-        
+
         The newly-created session should eventually be released by
-        a call to checkin().            
+        a call to checkin().
         '''
         sid, sess = self.newid(), dict()
-        self.cache.set(sid, sess)            
+        self.cache.set(sid, sess)
         self.checkedout[sid] = sess
         return sid, sess
 
         Therefore, it should eventually be released by a call to
         checkin().
 
-        @param sid Session id        
+        @param sid Session id
         '''
         # If we know it's already checked out, block.
         while sid in self.checkedout: self._lock.wait()
 
     @synchronized
     def shutdown(self):
-        '''Clean up outstanding sessions.'''        
+        '''Clean up outstanding sessions.'''
         if not self._closed:
             # Save or delete any sessions that are still out there.
             for sid, sess in self.checkedout.iteritems():
                 self.cache.set(sid, sess)
             self.checkedout.clear()
-            self.cache._cull()                
+            self.cache._cull()
             self._closed = True
 
     # Utilities
               str(random.randint(0, sys.maxint - 1)) + self._secret).hexdigest()
             if sid not in self.cache: break
         return sid
-            
+
 
 class SessionManager(object):
 
-    '''Session Manager.'''  
+    '''Session Manager.'''
 
     def __init__(self, cache, environ, **kw):
         self._cache = cache
             if self._sid is not None:
                 self._csid, self.inurl = value, True
                 if self._csid != self._sid: self.current = self.new = True
-        
+
     def _get(self, environ):
         '''Attempt to associate with an existing Session.'''
         # Try cookie first.
         if self.session is None:
             self._sid, self.session = self._cache.create()
             self.new = True
-    
+
     def close(self):
         '''Checks session back into session cache.'''
         # Check the session back in and get rid of our reference.
         self._cache.checkin(self._sid, self.session)
         self.session = None
-   
+
     def setcookie(self, headers):
-        '''Sets a cookie header if needed.''' 
+        '''Sets a cookie header if needed.'''
         cookie, name = SimpleCookie(), self._fieldname
         cookie[name], cookie[name]['path'] = self._sid, self._path
         headers.append(('Set-Cookie', cookie[name].OutputString()))
         else:
             self._qdict = {self._fieldname:self._sid}
         return '?'.join([path, urllib.urlencode(self._qdict)])
-        
+
 class _Session(object):
 
     '''WSGI middleware that adds a session service.'''
         environ[self.key] = sess
         try:
             # Return intial response if new or session id is random
-            if sess.new: return self._initial(environ, start_response)                
+            if sess.new: return self._initial(environ, start_response)
             return self.application(environ, start_response)
         # Always close session
-        finally:            
+        finally:
             sess.close()
-            
 
-class CookieSession(_Session):            
+
+class CookieSession(_Session):
 
     '''WSGI middleware that adds a session service in a cookie.'''
 
 
 
 class URLSession(_Session):
-    
+
     '''WSGI middleware that adds a session service in a URL query string.'''
 
     def _initial(self, environ, start_response):
         url = environ[self.key].seturl(environ)
         # Redirect to URL with session in query component
         start_response('302 Found', [('location', url)])
-        return ['The browser is being redirected to %s' % url]   
+        return ['The browser is being redirected to %s' % url]

File wsgistate/simple.py

 # Redistribution and use in source and binary forms, with or without modification,
 # are permitted provided that the following conditions are met:
 #
-#    1. Redistributions of source code must retain the above copyright notice, 
+#    1. Redistributions of source code must retain the above copyright notice,
 #       this list of conditions and the following disclaimer.
-#    
-#    2. Redistributions in binary form must reproduce the above copyright 
+#
+#    2. Redistributions in binary form must reproduce the above copyright
 #       notice, this list of conditions and the following disclaimer in the
 #       documentation and/or other materials provided with the distribution.
 #
 
 __all__ = ['SimpleCache', 'memoize', 'session', 'urlsession']
 
+def simplememo_deploy(global_conf, **kw):
+    '''Paste Deploy loader for caching.'''
+    def decorator(application):
+        _simple_memo_cache = SimpleCache(kw.get('cache'), **kw)
+        return WsgiMemoize(application, _simple_memo_cache, **kw)
+    return decorator
+
+def simplesess_deploy(global_conf, **kw):
+    '''Paste Deploy loader for sessions.'''
+    def decorator(application):
+        _simple_base_cache = SimpleCache(kw.get('cache'), **kw)
+        _simple_session_cache = SessionCache(_simple_base_cache, **kw)
+        return CookieSession(application, _simple_session_cache, **kw)
+    return decorator
+
+def simpleurlsess_deploy(global_conf, **kw):
+    '''Paste Deploy loader for URL encoded sessions.
+
+    @param initstr Database initialization string
+    '''
+    def decorator(application):
+        _simple_ubase_cache = SimpleCache(kw.get('cache'), **kw)
+        _simple_url_cache = SessionCache(_simple_ubase_cache, **kw)
+        return URLSession(application, _simple_url_cache, **kw)
+    return decorator
+
 def memoize(**kw):
     '''Decorator for caching.'''
     def decorator(application):
 
 class SimpleCache(BaseCache):
 
-    '''Single-process in-memory cache backend.'''    
-    
+    '''Single-process in-memory cache backend.'''
+
     def __init__(self, *a, **kw):
         super(SimpleCache, self).__init__(*a, **kw)
         # Get random seed
-        random.seed()        
+        random.seed()
         self._cache = dict()
         # Set max entries
         max_entries = kw.get('max_entries', 300)
         if values[0] < time.time():
             self.delete(key)
             return default
-        return values[1] 
+        return values[1]
 
     def set(self, key, value):
         '''Set a value in the cache.
 
         @param key Keyword of item in cache.
-        @param value Value to be inserted in cache.        
+        @param value Value to be inserted in cache.
         '''
         # Cull timed out values if over max # of entries
         if len(self._cache) >= self._max_entries: self._cull()
         return self._cache.keys()
 
     def _cull(self):
-        '''Remove items in cache to make room.'''        
+        '''Remove items in cache to make room.'''
         num, maxcull = 0, self._maxcull
         # Cull number of items allowed (set by self._maxcull)
         for key in self.keys():
         while len(self.keys()) >= self._max_entries and num <= maxcull:
             # Cull remainder of allowed quota at random
             self.delete(random.choice(self.keys()))
-            num += 1
+            num += 1

File wsgistate/tests/test_wsgistate.py

 # Redistribution and use in source and binary forms, with or without modification,
 # are permitted provided that the following conditions are met:
 #
-#    1. Redistributions of source code must retain the above copyright notice, 
+#    1. Redistributions of source code must retain the above copyright notice,
 #       this list of conditions and the following disclaimer.
-#    
-#    2. Redistributions in binary form must reproduce the above copyright 
+#
+#    2. Redistributions in binary form must reproduce the above copyright
 #       notice, this list of conditions and the following disclaimer in the
 #       documentation and/or other materials provided with the distribution.
 #
 import copy
 import os
 import time
-from wsgistate import *
 import urlparse
 
+from wsgistate import *
+
 
 class TestWsgiState(unittest.TestCase):
-    
+
     '''Test cases for wsgistate.'''
-        
+
     def dummy_sr(self, status, headers, exc_info=None):
         return headers
-    
+
     def my_app(self, environ, start_response):
         session = environ['com.saddi.service.session'].session
         count = session.get('count', 0) + 1
 
     def test_sc_set_getitem(self):
         '''Tests __setitem__ and __setitem__ on SimpleCache.'''
-        cache = simple.SimpleCache()
-        cache['test'] = 'test'
-        self.assertEqual(cache['test'], 'test')
+        testcache = simple.SimpleCache()
+        testcache['test'] = 'test'
+        self.assertEqual(testcache['test'], 'test')
 
     def test_sc_set_get(self):
         '''Tests set and get on SimpleCache.'''
-        cache = simple.SimpleCache()
-        cache.set('test', 'test')
-        self.assertEqual(cache.get('test'), 'test')
+        testcache = simple.SimpleCache()
+        testcache.set('test', 'test')
+        self.assertEqual(testcache.get('test'), 'test')
 
     def test_sc_delitem(self):
         '''Tests __delitem__ on SimpleCache.'''
-        cache = simple.SimpleCache()
-        cache['test'] = 'test'
-        del cache['test']
-        self.assertEqual(cache.get('test'), None)
+        testcache = simple.SimpleCache()
+        testcache['test'] = 'test'
+        del testcache['test']
+        self.assertEqual(testcache.get('test'), None)
 
     def test_sc_set_delete(self):
         '''Tests delete on SimpleCache.'''
-        cache = simple.SimpleCache()
-        cache.set('test', 'test')
-        cache.delete('test')
-        self.assertEqual(cache.get('test'), None)
+        testcache = simple.SimpleCache()
+        testcache.set('test', 'test')
+        testcache.delete('test')
+        self.assertEqual(testcache.get('test'), None)
 
     def test_set_getmany(self):
         '''Tests delete on SimpleCache.'''
-        cache = simple.SimpleCache()
-        cache.set('test', 'test')
-        cache.set('test2', 'test2')
-        self.assertEqual(sorted(cache.get_many(('test', 'test2')).values()), ['test', 'test2'])
+        testcache = simple.SimpleCache()
+        testcache.set('test', 'test')
+        testcache.set('test2', 'test2')
+        self.assertEqual(sorted(testcache.get_many(('test', 'test2')).values()), ['test', 'test2'])
 
     def test_sc_in_true(self):
         '''Tests in (true) on SimpleCache.'''
-        cache = simple.SimpleCache()
-        cache.set('test', 'test')
-        self.assertEqual('test' in cache, True)
+        testcache = simple.SimpleCache()
+        testcache.set('test', 'test')
+        self.assertEqual('test' in testcache, True)
 
     def test_sc_in_false(self):
         '''Tests in (false) on SimpleCache.'''
-        cache = simple.SimpleCache()
-        cache.set('test2', 'test')
-        self.assertEqual('test' in cache, False)
+        testcache = simple.SimpleCache()
+        testcache.set('test2', 'test')
+        self.assertEqual('test' in testcache, False)
 
     def test_sc_timeout(self):
         '''Tests timeout in SimpleCache.'''
-        cache = simple.SimpleCache(timeout=1)
-        cache.set('test', 'test')
+        testcache = simple.SimpleCache(timeout=1)
+        testcache.set('test', 'test')
         time.sleep(1)
-        self.assertEqual(cache.get('test'), None)        
+        self.assertEqual(testcache.get('test'), None)
 
     def test_mc_set_getitem(self):
         '''Tests __setitem__ and __setitem__ on MemoryCache.'''
-        cache = memory.MemoryCache()
-        cache['test'] = 'test'
-        self.assertEqual(cache['test'], 'test')
+        testcache = memory.MemoryCache()
+        testcache['test'] = 'test'
+        self.assertEqual(testcache['test'], 'test')
 
     def test_mc_set_get(self):
         '''Tests set and get on MemoryCache.'''
-        cache = memory.MemoryCache()
-        cache.set('test', 'test')
-        self.assertEqual(cache.get('test'), 'test')
+        testcache = memory.MemoryCache()
+        testcache.set('test', 'test')
+        self.assertEqual(testcache.get('test'), 'test')
 
     def test_mc_delitem(self):
         '''Tests __delitem__ on MemoryCache.'''
-        cache = memory.MemoryCache()
-        cache['test'] = 'test'
-        del cache['test']
-        self.assertEqual(cache.get('test'), None)
+        testcache = memory.MemoryCache()
+        testcache['test'] = 'test'
+        del testcache['test']
+        self.assertEqual(testcache.get('test'), None)
 
     def test_mc_set_delete(self):
         '''Tests delete on MemoryCache.'''
-        cache = memory.MemoryCache()
-        cache.set('test', 'test')
-        cache.delete('test')
-        self.assertEqual(cache.get('test'), None)
+        testcache = memory.MemoryCache()
+        testcache.set('test', 'test')
+        testcache.delete('test')
+        self.assertEqual(testcache.get('test'), None)
 
     def test_mc_set_getmany(self):
         '''Tests delete on MemoryCache.'''
-        cache = memory.MemoryCache()
-        cache.set('test', 'test')
-        cache.set('test2', 'test2')
-        self.assertEqual(sorted(cache.get_many(('test', 'test2')).values()), ['test', 'test2'])
+        testcache = memory.MemoryCache()
+        testcache.set('test', 'test')
+        testcache.set('test2', 'test2')
+        self.assertEqual(sorted(testcache.get_many(('test', 'test2')).values()), ['test', 'test2'])
 
     def test_mc_in_true(self):
         '''Tests in (true) on MemoryCache.'''
-        cache = memory.MemoryCache()
-        cache.set('test', 'test')
-        self.assertEqual('test' in cache, True)
+        testcache = memory.MemoryCache()
+        testcache.set('test', 'test')
+        self.assertEqual('test' in testcache, True)
 
     def test_mc_in_false(self):
         '''Tests in (false) on MemoryCache.'''
-        cache = memory.MemoryCache()
-        cache.set('test2', 'test')
-        self.assertEqual('test' in cache, False)
+        testcache = memory.MemoryCache()
+        testcache.set('test2', 'test')
+        self.assertEqual('test' in testcache, False)
 
     def test_mc_timeout(self):
         '''Tests timeout in MemoryCache.'''
-        cache = memory.MemoryCache(timeout=1)
-        cache.set('test', 'test')
+        testcache = memory.MemoryCache(timeout=1)
+        testcache.set('test', 'test')
         time.sleep(1)
-        self.assertEqual(cache.get('test'), None)           
+        self.assertEqual(testcache.get('test'), None)
 
     def test_fc_set_getitem(self):
         '''Tests __setitem__ and __setitem__ on FileCache.'''
-        cache = file.FileCache('test_wsgistate')
-        cache['test'] = 'test'
-        self.assertEqual(cache['test'], 'test')
+        testcache = file.FileCache('test_wsgistate')
+        testcache['test'] = 'test'
+        self.assertEqual(testcache['test'], 'test')
 
     def test_fc_set_get(self):
         '''Tests set and get on FileCache.'''
-        cache = file.FileCache('test_wsgistate')
-        cache.set('test', 'test')
-        self.assertEqual(cache.get('test'), 'test')
+        testcache = file.FileCache('test_wsgistate')
+        testcache.set('test', 'test')
+        self.assertEqual(testcache.get('test'), 'test')
 
     def test_fc_delitem(self):
         '''Tests __delitem__ on FileCache.'''
-        cache = file.FileCache('test_wsgistate')
-        cache['test'] = 'test'
-        del cache['test']
-        self.assertEqual(cache.get('test'), None)
+        testcache = file.FileCache('test_wsgistate')
+        testcache['test'] = 'test'
+        del testcache['test']
+        self.assertEqual(testcache.get('test'), None)
 
     def test_fc_set_delete(self):
         '''Tests delete on FileCache.'''
-        cache = file.FileCache('test_wsgistate')
-        cache.set('test', 'test')
-        cache.delete('test')
-        self.assertEqual(cache.get('test'), None)
+        testcache = file.FileCache('test_wsgistate')
+        testcache.set('test', 'test')
+        testcache.delete('test')
+        self.assertEqual(testcache.get('test'), None)
 
     def test_fc_set_getmany(self):
         '''Tests delete on FileCache.'''
-        cache = file.FileCache('test_wsgistate')
-        cache.set('test', 'test')
-        cache.set('test2', 'test2')
-        self.assertEqual(sorted(cache.get_many(('test', 'test2')).values()), ['test', 'test2'])
+        testcache = file.FileCache('test_wsgistate')
+        testcache.set('test', 'test')
+        testcache.set('test2', 'test2')
+        self.assertEqual(sorted(testcache.get_many(('test', 'test2')).values()), ['test', 'test2'])
 
     def test_fc_in_true(self):
         '''Tests in (true) on FileCache.'''
-        cache = file.FileCache('test_wsgistate')
-        cache.set('test', 'test')
-        self.assertEqual('test' in cache, True)
+        testcache = file.FileCache('test_wsgistate')
+        testcache.set('test', 'test')
+        self.assertEqual('test' in testcache, True)
 
     def test_fc_in_false(self):
         '''Tests in (false) on FileCache.'''
-        cache = file.FileCache('test_wsgistate')
-        cache.set('test2', 'test')
-        self.assertEqual('test' in cache, False)
+        testcache = file.FileCache('test_wsgistate')
+        testcache.set('test2', 'test')
+        self.assertEqual('test' in testcache, False)
 
     def test_fc_timeout(self):
         '''Tests timeout in FileCache.'''
-        cache = file.FileCache('test_wsgistate', timeout=1)
-        cache.set('test', 'test')
+        testcache = file.FileCache('test_wsgistate', timeout=1)
+        testcache.set('test', 'test')
         time.sleep(1)
-        self.assertEqual(cache.get('test'), None)           
-    
+        self.assertEqual(testcache.get('test'), None)
+
     def test_db_set_getitem(self):
         '''Tests __setitem__ and __setitem__ on DbCache.'''
-        cache = db.DbCache('sqlite:///:memory:')
-        cache['test'] = 'test'
-        self.assertEqual(cache['test'], 'test')
+        testcache = db.DbCache('sqlite://')
+        testcache['test'] = 'test'
+        self.assertEqual(testcache['test'], 'test')
 
     def test_db_set_get(self):
         '''Tests set and get on DbCache.'''
-        cache = db.DbCache('sqlite:///:memory:')
-        cache.set('test', 'test')
-        self.assertEqual(cache.get('test'), 'test')
+        testcache = db.DbCache('sqlite://')
+        testcache.set('test', 'test')
+        self.assertEqual(testcache.get('test'), 'test')
 
     def test_db_delitem(self):
         '''Tests __delitem__ on DbCache.'''
-        cache = db.DbCache('sqlite:///:memory:')
-        cache['test'] = 'test'
-        del cache['test']
-        self.assertEqual(cache.get('test'), None)
+        testcache = db.DbCache('sqlite://')
+        testcache['test'] = 'test'
+        del testcache['test']
+        self.assertEqual(testcache.get('test'), None)
 
     def test_db_set_delete(self):
         '''Tests delete on DbCache.'''
-        cache = db.DbCache('sqlite:///:memory:')
-        cache.set('test', 'test')
-        cache.delete('test')
-        self.assertEqual(cache.get('test'), None)
+        testcache = db.DbCache('sqlite://')
+        testcache.set('test', 'test')
+        testcache.delete('test')
+        self.assertEqual(testcache.get('test'), None)
 
     def test_db_set_getmany(self):
         '''Tests delete on DbCache.'''
-        cache = db.DbCache('sqlite:///:memory:')
-        cache.set('test', 'test')
-        cache.set('test2', 'test2')
-        self.assertEqual(sorted(cache.get_many(('test', 'test2')).values()), ['test', 'test2'])
+        testcache = db.DbCache('sqlite://')
+        testcache.set('test', 'test')
+        testcache.set('test2', 'test2')
+        self.assertEqual(
+            sorted(testcache.get_many(('test', 'test2'))),
+                ['test', 'test2']
+        )
 
     def test_db_in_true(self):
         '''Tests in (true) on DbCache.'''
-        cache = db.DbCache('sqlite:///:memory:')
-        cache.set('test', 'test')
-        self.assertEqual('test' in cache, True)
+        testcache = db.DbCache('sqlite://')
+        testcache.set('test', 'test')
+        self.assertEqual('test' in testcache, True)
 
     def test_db_in_false(self):
         '''Tests in (false) on DbCache.'''
-        cache = db.DbCache('sqlite:///:memory:')
-        cache.set('test2', 'test')
-        self.assertEqual('test' in cache, False)
+        testcache = db.DbCache('sqlite://')
+        testcache.set('test2', 'flasmburbert')
+        self.assertEqual('flasmburbert' in testcache, False)
 
     def test_db_timeout(self):
         '''Tests timeout in DbCache.'''
-        cache = db.DbCache('sqlite:///:memory:', timeout=1)
-        cache.set('test', 'test')
+        testcache = db.DbCache('sqlite://', timeout=1)
+        testcache.set('test', 'test')
         time.sleep(2)
-        self.assertEqual(cache.get('test'), None)         
+        self.assertEqual(testcache.get('test'), None)
 
     def test_mcd_set_getitem(self):
         '''Tests __setitem__ and __setitem__ on MemCache.'''
-        cache = memcached.MemCached('localhost')
-        cache['test'] = 'test'
-        self.assertEqual(cache['test'], 'test')
+        testcache = memcached.MemCached('localhost')
+        testcache['test'] = 'test'
+        self.assertEqual(testcache['test'], 'test')
 
     def test_mcd_set_get(self):
         '''Tests set and get on MemCache.'''
-        cache = memcached.MemCached('localhost')
-        cache.set('test', 'test')
-        self.assertEqual(cache.get('test'), 'test')
+        testcache = memcached.MemCached('localhost')
+        testcache.set('test', 'test')
+        self.assertEqual(testcache.get('test'), 'test')
 
     def test_mcd_delitem(self):
         '''Tests __delitem__ on MemCache.'''
-        cache = memcached.MemCached('localhost')
-        cache['test'] = 'test'
-        del cache['test']
-        self.assertEqual(cache.get('test'), None)
+        testcache = memcached.MemCached('localhost')
+        testcache['test'] = 'test'
+        del testcache['test']
+        self.assertEqual(testcache.get('test'), None)
 
     def test_mcd_set_delete(self):
         '''Tests delete on MemCache.'''
-        cache = memcached.MemCached('localhost')
-        cache.set('test', 'test')
-        cache.delete('test')
-        self.assertEqual(cache.get('test'), None)
+        testcache = memcached.MemCached('localhost')
+        testcache.set('test', 'test')
+        testcache.delete('test')
+        self.assertEqual(testcache.get('test'), None)
 
     def test_mcd_set_getmany(self):
         '''Tests delete on MemCache.'''
-        cache = memcached.MemCached('localhost')
-        cache.set('test', 'test')
-        cache.set('test2', 'test2')
-        self.assertEqual(sorted(cache.get_many(('test', 'test2')).values()), ['test', 'test2'])
+        testcache = memcached.MemCached('localhost')
+        testcache.set('test', 'test')
+        testcache.set('test2', 'test2')
+        self.assertEqual(sorted(testcache.get_many(('test', 'test2')).values()), ['test', 'test2'])
 
     def test_mcd_in_true(self):
         '''Tests in (true) on MemCache.'''
-        cache = memcached.MemCached('localhost')
-        cache.set('test', 'test')
-        self.assertEqual('test' in cache, True)
+        testcache = memcached.MemCached('localhost')
+        testcache.set('test', 'test')
+        self.assertEqual('test' in testcache, True)
 
     def test_mcd_in_false(self):
         '''Tests in (false) on MemCache.'''
-        cache = memcached.MemCached('localhost')
-        cache.set('test2', 'test')
-        self.assertEqual('test' in cache, False)
+        testcache = memcached.MemCached('localhost')
+        testcache.set('test2', 'test')
+        self.assertEqual('test' in testcache, False)
 
     def test_mcb_timeout(self):
         '''Tests timeout in DbCache.'''
-        cache = memcached.MemCached('localhost', timeout=1)
-        cache.set('test', 'test')
+        testcache = memcached.MemCached('localhost', timeout=1)
+        testcache.set('test', 'test')
         time.sleep(1)
-        self.assertEqual(cache.get('test'), None)          
+        self.assertEqual(testcache.get('test'), None)
 
     def test_cookiesession_sc(self):
         '''Tests session cookies with SimpleCache.'''
         testc = simple.SimpleCache()
-        cache = session.SessionCache(testc)
-        csession = session.CookieSession(self.my_app, cache)
+        testcache = session.SessionCache(testc)
+        csession = session.CookieSession(self.my_app, testcache)
         cookie = csession({}, self.dummy_sr)['cookie']
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
     def test_cookiesession_mc(self):
         '''Tests session cookies with MemoryCache.'''
         testc = memory.MemoryCache()
-        cache = session.SessionCache(testc)
-        csession = session.CookieSession(self.my_app, cache)
+        testcache = session.SessionCache(testc)
+        csession = session.CookieSession(self.my_app, testcache)
         cookie = csession({}, self.dummy_sr)['cookie']
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
         self.assertEqual(result['count'], 4)
-        
+
     def test_cookiesession_fc(self):
         '''Tests session cookies with FileCache.'''
         testc = file.FileCache('test_wsgistate')
-        cache = session.SessionCache(testc)
-        csession = session.CookieSession(self.my_app, cache)
+        testcache = session.SessionCache(testc)
+        csession = session.CookieSession(self.my_app, testcache)
         cookie = csession({}, self.dummy_sr)['cookie']
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
 
     def test_cookiesession_dc(self):
         '''Tests session cookies with DbCache.'''
-        testc = db.DbCache('sqlite:///:memory:')
-        cache = session.SessionCache(testc)
-        csession = session.CookieSession(self.my_app, cache)
+        testc = db.DbCache('sqlite://')
+        testcache = session.SessionCache(testc)
+        csession = session.CookieSession(self.my_app, testcache)
         cookie = csession({}, self.dummy_sr)['cookie']
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
     def test_cookiesession_mdc(self):
         '''Tests session cookies with MemCached.'''
         testc = memcached.MemCached('localhost')
-        cache = session.SessionCache(testc)
-        csession = session.CookieSession(self.my_app, cache)
+        testcache = session.SessionCache(testc)
+        csession = session.CookieSession(self.my_app, testcache)
         cookie = csession({}, self.dummy_sr)['cookie']
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
         csession({'HTTP_COOKIE':cookie}, self.dummy_sr)
         result = tapp({'HTTP_COOKIE':cookie}, self.dummy_sr)
         self.assertEqual(result['count'], 4)
 
-    def test_dec_cookiesession_mc(self):
+    def test_dec_cookiesession_memc(self):
         '''Tests session cookies with MemoryCache decorator.'''
         @memory.session()
         def tapp(environ, start_response):
 
     def test_dec_cookiesession_db(self):
         '''Tests session cookies with DbCache decorator.'''
-        @db.session('sqlite:///:memory:')
+        @db.session('sqlite://')
         def tapp(environ, start_response):
             session = environ['com.saddi.service.session'].session
             count = session.get('count', 0) + 1
         tapp({'HTTP_COOKIE':cookie}, self.dummy_sr)
         tapp({'HTTP_COOKIE':cookie}, self.dummy_sr)
         result = tapp({'HTTP_COOKIE':cookie}, self.dummy_sr)
-        self.assertEqual(result['count'], 4)          
+        self.assertEqual(result['count'], 4)
 
     def test_random_cookiesession_sc(self):
         '''Tests random session cookies with SimpleCache.'''
         testc = simple.SimpleCache()
-        cache = session.SessionCache(testc, random=True)
-        csession = session.CookieSession(self.my_app, cache)
+        testcache = session.SessionCache(testc, random=True)
+        csession = session.CookieSession(self.my_app, testcache)
         result = csession({}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
     def test_random_cookiesession_mc(self):
         '''Tests random session cookies with MemoryCache.'''
         testc = memory.MemoryCache()
-        cache = session.SessionCache(testc, random=True)
-        csession = session.CookieSession(self.my_app, cache)
+        testcache = session.SessionCache(testc, random=True)
+        csession = session.CookieSession(self.my_app, testcache)
         result = csession({}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
         self.assertEqual(result['count'], 4)
-        
+
     def test_random_cookiesession_fc(self):
         '''Tests random session cookies with FileCache.'''
         testc = file.FileCache('test_wsgistate')
-        cache = session.SessionCache(testc, random=True)
-        csession = session.CookieSession(self.my_app, cache)
+        testcache = session.SessionCache(testc, random=True)
+        csession = session.CookieSession(self.my_app, testcache)
         result = csession({}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
 
     def test_random_cookiesession_dc(self):
         '''Tests random session cookies with DbCache.'''
-        testc = db.DbCache('sqlite:///:memory:')
-        cache = session.SessionCache(testc, random=True)
-        csession = session.CookieSession(self.my_app, cache)
+        testc = db.DbCache('sqlite://')
+        testcache = session.SessionCache(testc, random=True)
+        csession = session.CookieSession(self.my_app, testcache)
         result = csession({}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
     def test_random_cookiesession_mdc(self):
         '''Tests random session cookies with MemCached.'''
         testc = memcached.MemCached('localhost')
-        cache = session.SessionCache(testc, random=True)
-        csession = session.CookieSession(self.my_app, cache)
+        testcache = session.SessionCache(testc, random=True)
+        csession = session.CookieSession(self.my_app, testcache)
         result = csession({}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
         result = csession({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
 
     def test_dec_random_cookiesession_db(self):
         '''Tests random session cookies with DbCache decorator.'''
-        @db.session('sqlite:///:memory:', random=True)
+        @db.session('sqlite://', random=True)
         def tapp(environ, start_response):
             session = environ['com.saddi.service.session'].session
             count = session.get('count', 0) + 1
         result = tapp({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
         result = tapp({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
         result = tapp({'HTTP_COOKIE':result['cookie']}, self.dummy_sr)
-        self.assertEqual(result['count'], 4)                
+        self.assertEqual(result['count'], 4)
 
     def test_urlsession_sc(self):
         '''Tests URL encoded sessions with SimpleCache.'''
         testc = simple.SimpleCache()
-        cache = session.SessionCache(testc)
-        csession = session.URLSession(self.my_app2, cache)
+        testcache = session.SessionCache(testc)
+        csession = session.URLSession(self.my_app2, testcache)
         url = csession({}, self.dummy_sr)[0].split()[-1]
         query = urlparse.urlsplit(url)[3]
         csession({'QUERY_STRING':query}, self.dummy_sr)
     def test_urlsession_mc(self):
         '''Tests URL encoded sessions with MemoryCache.'''
         testc = memory.MemoryCache()
-        cache = session.SessionCache(testc)
-        csession = session.URLSession(self.my_app2, cache)
+        testcache = session.SessionCache(testc)
+        csession = session.URLSession(self.my_app2, testcache)
         url = csession({}, self.dummy_sr)[0].split()[-1]
         query = urlparse.urlsplit(url)[3]
         csession({'QUERY_STRING':query}, self.dummy_sr)
         csession({'QUERY_STRING':query}, self.dummy_sr)
         result = csession({'QUERY_STRING':query}, self.dummy_sr)
         self.assertEqual(result['count'], 4)
-        
+
     def test_urlsession_fc(self):
         '''Tests URL encoded sessions with FileCache.'''
         testc = file.FileCache('test_wsgistate')
-        cache = session.SessionCache(testc)
-        csession = session.URLSession(self.my_app2, cache)
+        testcache = session.SessionCache(testc)
+        csession = session.URLSession(self.my_app2, testcache)
         url = csession({}, self.dummy_sr)[0].split()[-1]
         query = urlparse.urlsplit(url)[3]
         csession({'QUERY_STRING':query}, self.dummy_sr)
 
     def test_urlsession_dc(self):
         '''Tests URL encoded sessions with DbCache.'''
-        testc = db.DbCache('sqlite:///:memory:')
-        cache = session.SessionCache(testc)
-        csession = session.URLSession(self.my_app2, cache)
+        testc = db.DbCache('sqlite://')
+        testcache = session.SessionCache(testc)
+        csession = session.URLSession(self.my_app2, testcache)
         url = csession({}, self.dummy_sr)[0].split()[-1]
         query = urlparse.urlsplit(url)[3]
         csession({'QUERY_STRING':query}, self.dummy_sr)
     def test_urlsession_mdc(self):
         '''Tests URL encoded sessions with MemCached.'''
         testc = memcached.MemCached('localhost')
-        cache = session.SessionCache(testc)
-        csession = session.URLSession(self.my_app2, cache)
+        testcache = session.SessionCache(testc)
+        csession = session.URLSession(self.my_app2, testcache)
         url = csession({}, self.dummy_sr)[0].split()[-1]
         query = urlparse.urlsplit(url)[3]
         csession({'QUERY_STRING':query}, self.dummy_sr)
         csession({'QUERY_STRING':query}, self.dummy_sr)
         result = csession({'QUERY_STRING':query}, self.dummy_sr)
         self.assertEqual(result['count'], 4)
-        
+
     def test_dec_urlsession_fc(self):
         '''Tests URL encoded sessions with FileCache decorator.'''
         @file.urlsession('test_wsgistate')
 
     def test_dec_urlsession_dc(self):
         '''Tests URL encoded sessions with DbCache decorator.'''
-        @db.urlsession('sqlite:///:memory:')
+        @db.urlsession('sqlite://')
         def csession(environ, start_response):
             session = environ['com.saddi.service.session'].session
             count = session.get('count', 0) + 1
         csession({'QUERY_STRING':query}, self.dummy_sr)
         csession({'QUERY_STRING':query}, self.dummy_sr)
         result = csession({'QUERY_STRING':query}, self.dummy_sr)
-        self.assertEqual(result['count'], 4)        
+        self.assertEqual(result['count'], 4)
 
     def test_wsgimemoize_default_sc(self):
         '''Tests default memoizing with SimpleCache decorator.'''
 
     def test_wsgimemoize_default_db(self):
         '''Tests default memoizing with DbCache.'''
-        testc = db.DbCache('sqlite:///:memory:')
+        testc = db.DbCache('sqlite://')
         env = {'PATH_INFO':'/', 'REQUEST_METHOD':'GET'}
         cacheapp = cache.WsgiMemoize(self.my_app3, testc)
         result1 = cacheapp(env, self.dummy_sr)
 
     def test_dec_wsgimemoize_default_db(self):
         '''Tests default memoizing with DbCache.'''
-        @db.memoize('sqlite:///:memory:')
+        @db.memoize('sqlite://')
         def cacheapp(environ, start_response):
             start_response('200 OK', [])
             return ['passed']
         env = {'PATH_INFO':'/', 'REQUEST_METHOD':'GET'}
         result1 = cacheapp(env, self.dummy_sr)
         result2 = cacheapp(env, self.dummy_sr)
-        self.assertEqual(result1 == result2, True)        
+        self.assertEqual(result1 == result2, True)
 
     def test_wsgimemoize_method_sc(self):
         '''Tests memoizing with HTTP method as part of the key with SimpleCache.'''
 
     def test_wsgimemoize_method_db(self):
         '''Tests memoizing with HTTP method as part of the key with DbCache.'''
-        testc = db.DbCache('sqlite:///:memory:')
+        testc = db.DbCache('sqlite://')
         env = {'PATH_INFO':'/', 'REQUEST_METHOD':'GET'}
         cacheapp = cache.WsgiMemoize(self.my_app3, testc, key_methods=True)
         result1 = cacheapp(env, self.dummy_sr)
 
     def test_wsgimemoize_user_info_db(self):
         '''Tests memoizing with user info as part of the key with DbCache.'''
-        testc = db.DbCache('sqlite:///:memory:')
+        testc = db.DbCache('sqlite://')
         env = {'PATH_INFO':'/', 'REQUEST_METHOD':'GET',
         'wsgi.input':StringIO.StringIO('num=12121&str1=test&state=NV&Submit=Submit')}
         cacheapp = cache.WsgiMemoize(self.my_app3, testc, key_user_info=True)
         self.assertEqual(result1 == result2, True)
 
     def test_public(self):
-        '''Tests correct setting of Cache-Control header "public".'''        
+        '''Tests correct setting of Cache-Control header "public".'''
         @cache.public
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
         self.assertEqual(result['Cache-Control'], 'public')
-                                
+
     def test_private(self):
         '''Tests correct setting of Cache-Control header "private".'''
         @cache.private
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
         self.assertEqual(result['Cache-Control'], 'private')
-    
+
     def test_nocache(self):
         '''Tests correct setting of Cache-Control header "no-cache".'''
         @cache.nocache
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
         self.assertEqual(result['Cache-Control'], 'no-cache')
 
         @cache.nostore
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
         self.assertEqual(result['Cache-Control'], 'no-store')
 
         @cache.notransform
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
         self.assertEqual(result['Cache-Control'], 'no-transform')
 
         @cache.revalidate
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
-        self.assertEqual(result['Cache-Control'], 'must-revalidate')              
+        self.assertEqual(result['Cache-Control'], 'must-revalidate')
 
     def test_proxyrevalidate(self):
         '''Tests correct setting of Cache-Control header "proxy-revalidate".'''
         @cache.proxyrevalidate
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
         self.assertEqual(result['Cache-Control'], 'proxy-revalidate')
 
         @cache.maxage(30)
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
         self.assertEqual(result['Cache-Control'], 'max-age=30')
 
         @cache.smaxage(30)
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
         self.assertEqual(result['Cache-Control'], 's-maxage=30')
 
         @cache.vary(['Content-type'])
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
         self.assertEqual(result['Vary'], 'Content-type')
 
         @cache.modified(30)
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
-        self.assertEqual('Modified' in result, True)        
+        self.assertEqual('Modified' in result, True)
 
     def test_cachecontrol_combo(self):
         '''Tests correct setting of two Cache Control header settings.'''
         @cache.private
         def app(environ, start_response):
             headers = start_response('200 OK', [])
-            if headers: environ['headers'] = headers 
-            return environ    
+            if headers: environ['headers'] = headers
+            return environ
         result = dict(app({'REQUEST_METHOD':'GET'}, self.dummy_sr)['headers'])
-        self.assertEqual(result['Cache-Control'], 's-maxage=30, private')         
+        self.assertEqual(result['Cache-Control'], 's-maxage=30, private')
 
-    'modified'        
+    'modified'
 
 if __name__ == '__main__':
     unittest.main()
     try:
         os.rmdir('test_wsgistate')
-    except IOError: pass
+    except IOError: pass