From 9fcbab5e19ab8491a6d2f3db98e89eb6ad7452c6 Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine Date: Wed, 11 Feb 2009 19:54:59 +0000 Subject: [PATCH 1/3] Better name for inner functions --- lib/GenericCache/decorators.py | 8 ++++---- lib/cache.py | 8 ++++---- lib/profiler.py | 6 +++--- lib/registry.py | 6 +++--- lib/security.py | 4 ++-- lib/utils.py | 8 ++++---- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/GenericCache/decorators.py b/lib/GenericCache/decorators.py index 485975d..7c5035f 100644 --- a/lib/GenericCache/decorators.py +++ b/lib/GenericCache/decorators.py @@ -21,12 +21,12 @@ def cached(cache, marshaller = default_marshaller): The marshaller computes a key from function arguments """ def decorator(func): - def inner(*args, **kwargs): + def inner_cached(*args, **kwargs): key = marshaller(func, *args, **kwargs) return cache.fetch_with_generator(key, func, *args, **kwargs) - return inner + return inner_cached return decorator def verbose(func): @@ -48,7 +48,7 @@ def synchronized(func): """ Synchronize a method using internal lock object, a decorator """ - def inner(self, *args, **kwargs): + def inner_synchronized(self, *args, **kwargs): """ The inner function """ @@ -57,5 +57,5 @@ def synchronized(func): return func(self, *args, **kwargs) finally: self.lock.release() - return inner + return inner_synchronized diff --git a/lib/cache.py b/lib/cache.py index 4ff5063..cfe9159 100644 --- a/lib/cache.py +++ b/lib/cache.py @@ -71,12 +71,12 @@ def request(marshaller = local_marshaller): Cache in the request object """ def decorator(func): - def inner(*args, **kwargs): + def inner_request(*args, **kwargs): key = marshaller(func, *args, **kwargs) cache = get_request_cache() return cache.fetch_with_generator(key, func, *args, **kwargs) - return inner + return inner_request return decorator def static(marshaller = local_marshaller): @@ -96,14 +96,14 @@ def autoexpire(marshaller = local_marshaller): Cache in transient cache, but expire if node changed """ def decorator(func): - def inner(self, *args, **kwargs): + def inner_autoexpire(self, *args, **kwargs): if self.has_changed(): self.clear_cache() key = marshaller(func, self, *args, **kwargs) cache = _transient_cache return cache.fetch_with_generator(key, func, self, *args, **kwargs) - return inner + return inner_autoexpire return decorator diff --git a/lib/profiler.py b/lib/profiler.py index 9174b90..86ffaec 100644 --- a/lib/profiler.py +++ b/lib/profiler.py @@ -36,7 +36,7 @@ class Profiler(object): Profile a function """ name = "%s:%s" % (klass.__name__, function.__name__) - def inner(*args, **kwargs): + def inner_profile(*args, **kwargs): start = time.time() try: return function(*args, **kwargs) @@ -47,8 +47,8 @@ class Profiler(object): count += (end - start) self.calls[name] = (count, nb) if getattr(function, "exposed", None): - inner.exposed = True - return inner + inner_profile.exposed = True + return inner_profile def get(self): diff --git a/lib/registry.py b/lib/registry.py index c0b7ab0..ff88cde 100644 --- a/lib/registry.py +++ b/lib/registry.py @@ -46,7 +46,7 @@ def register(klass): for name, template in klass.templates.items(): template = kid.load_template('kid/%s.kid' % template, cache = 1) def caller(template): - def inner(self, **kwargs): + def inner_register(self, **kwargs): # Bind useful variables kwargs["context"] = self kwargs["trn"] = self.translate @@ -55,8 +55,8 @@ def register(klass): tmpl = template.Template(**kwargs) return tmpl.serialize(encoding='utf-8', output='xhtml-strict') - inner.exposed = 1 - return inner + inner_register.exposed = 1 + return inner_register setattr(klass, name, caller(template)) # Add to resolutions diff --git a/lib/security.py b/lib/security.py index 0c3ee65..c4e939b 100644 --- a/lib/security.py +++ b/lib/security.py @@ -266,10 +266,10 @@ def protected(role): """ ALL_ROLES.add(role) def decorator(func): - def inner(self, *args, **kwargs): + def inner_protected(self, *args, **kwargs): if not self.has_role(role): raise Unauthorized, "operation requires role %s" % role else: return func(self, *args, **kwargs) - return inner + return inner_protected return decorator diff --git a/lib/utils.py b/lib/utils.py index 125671a..adab8af 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -196,7 +196,7 @@ def verbose(func): """ Verbose decorator for debug """ - def inner(*args, **kwargs): + def inner_verbose(*args, **kwargs): print func.__name__, args, kwargs try: res = func(*args, **kwargs) @@ -205,7 +205,7 @@ def verbose(func): except Exception, e: print func.__name__, args, kwargs, "=> !!ERROR ", e raise - return inner + return inner_verbose def failsafe(default): """ @@ -213,13 +213,13 @@ def failsafe(default): Will return default in case of error """ def decorator(func): - def inner(*args, **kwargs): + def inner_failsafe(*args, **kwargs): try: return func(*args, **kwargs) except Exception, e: error(func.__name__, e) return default - return inner + return inner_failsafe return decorator -- 1.6.1.2