summaryrefslogtreecommitdiffstats
path: root/module/lib/beaker/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/lib/beaker/util.py')
-rw-r--r--module/lib/beaker/util.py41
1 files changed, 21 insertions, 20 deletions
diff --git a/module/lib/beaker/util.py b/module/lib/beaker/util.py
index 0bd82bb85..04c9617c5 100644
--- a/module/lib/beaker/util.py
+++ b/module/lib/beaker/util.py
@@ -16,7 +16,7 @@ import warnings
import sys
py3k = getattr(sys, 'py3kwarning', False) or sys.version_info >= (3, 0)
-py24 = sys.version_info < (2, 5)
+py24 = sys.version_info < (2,5)
jython = sys.platform.startswith('java')
if py3k or jython:
@@ -45,6 +45,7 @@ def verify_directory(dir):
if tries > 5:
raise
+
def deprecated(message):
def wrapper(fn):
def deprecated_method(*args, **kargs):
@@ -55,7 +56,7 @@ def deprecated(message):
deprecated_method.__doc__ = "%s\n\n%s" % (message, fn.__doc__)
return deprecated_method
return wrapper
-
+
class ThreadLocal(object):
"""stores a value on a per-thread basis"""
@@ -63,25 +64,25 @@ class ThreadLocal(object):
def __init__(self):
self._tlocal = _tlocal()
-
+
def put(self, value):
self._tlocal.value = value
-
+
def has(self):
return hasattr(self._tlocal, 'value')
-
+
def get(self, default=None):
return getattr(self._tlocal, 'value', default)
-
+
def remove(self):
del self._tlocal.value
-
+
class SyncDict(object):
"""
An efficient/threadsafe singleton map algorithm, a.k.a.
"get a value based on this key, and create if not found or not
valid" paradigm:
-
+
exists && isvalid ? get : create
Designed to work with weakref dictionaries to expect items
@@ -95,7 +96,7 @@ class SyncDict(object):
def __init__(self):
self.mutex = _thread.allocate_lock()
self.dict = {}
-
+
def get(self, key, createfunc, *args, **kwargs):
try:
if self.has_key(key):
@@ -124,7 +125,7 @@ class SyncDict(object):
def has_key(self, key):
return self.dict.has_key(key)
-
+
def __contains__(self, key):
return self.dict.__contains__(key)
def __getitem__(self, key):
@@ -145,30 +146,30 @@ class WeakValuedRegistry(SyncDict):
sha1 = None
def encoded_path(root, identifiers, extension = ".enc", depth = 3,
digest_filenames=True):
-
+
"""Generate a unique file-accessible path from the given list of
identifiers starting at the given root directory."""
ident = "_".join(identifiers)
-
+
global sha1
if sha1 is None:
from beaker.crypto import sha1
-
+
if digest_filenames:
if py3k:
ident = sha1(ident.encode('utf-8')).hexdigest()
else:
ident = sha1(ident).hexdigest()
-
+
ident = os.path.basename(ident)
tokens = []
for d in range(1, depth):
tokens.append(ident[0:d])
-
+
dir = os.path.join(root, *tokens)
verify_directory(dir)
-
+
return os.path.join(dir, ident + extension)
@@ -250,7 +251,7 @@ def coerce_cache_params(params):
def parse_cache_config_options(config, include_defaults=True):
"""Parse configuration options and validate for use with the
CacheManager"""
-
+
# Load default cache options
if include_defaults:
options= dict(type='memory', data_dir=None, expire=None,
@@ -263,11 +264,11 @@ def parse_cache_config_options(config, include_defaults=True):
if key.startswith('cache.'):
options[key[6:]] = val
coerce_cache_params(options)
-
+
# Set cache to enabled if not turned off
if 'enabled' not in options:
options['enabled'] = True
-
+
# Configure region dict if regions are available
regions = options.pop('regions', None)
if regions:
@@ -294,7 +295,7 @@ def func_namespace(func):
if hasattr(func, 'im_func'):
kls = func.im_class
func = func.im_func
-
+
if kls:
return '%s.%s' % (kls.__module__, kls.__name__)
else: