From 95a38b5bc9b6ba79dd5257e32d939bd94298964e Mon Sep 17 00:00:00 2001 From: tobes Date: Thu, 2 Aug 2012 08:51:22 +0100 Subject: [PATCH] Store the message plus better names --- ckan/lib/maintain.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ckan/lib/maintain.py b/ckan/lib/maintain.py index 9101e637b18..efaafe45018 100644 --- a/ckan/lib/maintain.py +++ b/ckan/lib/maintain.py @@ -62,29 +62,31 @@ def deprecate_context_item(item_name, message=''): # prevent a circular import from ckan.lib.base import c - class Fake(object): + class WrappedContextItem(object): ''' This is a fake object that calls the methods of the object contained. ''' - def __init__(self, obj): - self._obj = obj - def __getattribute__(self,name): + def __init__(self, obj, message): + self._ckan_obj = obj + self._ckan_message = message + def __getattribute__(self, name): + message = object.__getattribute__(self, '_ckan_message') log.warning('c.%s has been deprecated. %s', item_name, message) - obj = object.__getattribute__(self, '_obj') + obj = object.__getattribute__(self, '_ckan_obj') # hack to get the actual object when needed - if name == '_obj': + if name == '_ckan_obj': return obj return getattr(obj, name) # store the value in a fake object - setattr(c, item_name, Fake(getattr(c, item_name))) + setattr(c, item_name, WrappedContextItem(getattr(c, item_name), message)) # we need to store the origional __getattr__ and replace with our own one if not hasattr(c.__class__, '__old_getattr__'): def fake_attr(self, name): obj = self.__class__.__dict__['__old_getattr__'](self, name) - if isinstance(obj, Fake): - return obj._obj + if isinstance(obj, WrappedContextItem): + return obj._ckan_obj else: return obj get_attr = getattr(c.__class__, '__getattr__')