diff --git a/ckan/lib/maintain.py b/ckan/lib/maintain.py index efaafe45018..6920720bf5e 100644 --- a/ckan/lib/maintain.py +++ b/ckan/lib/maintain.py @@ -62,34 +62,10 @@ def deprecate_context_item(item_name, message=''): # prevent a circular import from ckan.lib.base import c - class WrappedContextItem(object): - ''' This is a fake object that calls the methods of the object - contained. ''' - def __init__(self, obj, message): - self._ckan_obj = obj - self._ckan_message = message - def __getattribute__(self, name): - message = object.__getattribute__(self, '_ckan_message') + def get_item(self): + if self == c: log.warning('c.%s has been deprecated. %s', item_name, message) - obj = object.__getattribute__(self, '_ckan_obj') - # hack to get the actual object when needed - if name == '_ckan_obj': - return obj - return getattr(obj, name) - - - # store the value in a fake object - 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, WrappedContextItem): - return obj._ckan_obj - else: - return obj - get_attr = getattr(c.__class__, '__getattr__') - setattr(c.__class__, '__old_getattr__', get_attr) - setattr(c.__class__, '__getattr__', fake_attr) + return getattr(self._current_obj(), item_name) + + setattr(c.__class__, item_name, property(get_item))