Commit 2fe2a54f authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[adapters] fix #1424467 caused by precedence of bw compat method while the...

[adapters] fix #1424467 caused by precedence of bw compat method while the adapter is concret for a given class

--HG--
branch : stable
parent 2e52db5cdbde
......@@ -68,6 +68,7 @@ class IEmailableAdapter(EntityAdapter):
class INotifiableAdapter(EntityAdapter):
__needs_bw_compat__ = True
__regid__ = 'INotifiable'
__select__ = is_instance('Any')
......@@ -157,6 +158,7 @@ def merge_weight_dict(maindict, newdict):
class IDownloadableAdapter(EntityAdapter):
"""interface for downloadable entities"""
__needs_bw_compat__ = True
__regid__ = 'IDownloadable'
__select__ = implements(IDownloadable, warn=False) # XXX for bw compat, else should be abstract
......@@ -208,6 +210,7 @@ class ITreeAdapter(EntityAdapter):
.. automethod: children_rql
.. automethod: path
"""
__needs_bw_compat__ = True
__regid__ = 'ITree'
__select__ = implements(ITree, warn=False) # XXX for bw compat, else should be abstract
......@@ -335,8 +338,8 @@ class ITreeAdapter(EntityAdapter):
for entity in child.cw_adapt_to('ITree').prefixiter(_done):
yield entity
@cached
@implements_adapter_compat('ITree')
@cached
def path(self):
"""Returns the list of eids from the root object to this object."""
path = []
......@@ -366,6 +369,7 @@ class IProgressAdapter(EntityAdapter):
You should at least override progress_info an in_progress methods on concret
implementations.
"""
__needs_bw_compat__ = True
__regid__ = 'IProgress'
__select__ = implements(IProgress, warn=False) # XXX for bw compat, should be abstract
......@@ -434,6 +438,7 @@ class IProgressAdapter(EntityAdapter):
class IMileStoneAdapter(IProgressAdapter):
__needs_bw_compat__ = True
__regid__ = 'IMileStone'
__select__ = implements(IMileStone, warn=False) # XXX for bw compat, should be abstract
......
......@@ -20,6 +20,7 @@
__docformat__ = "restructuredtext en"
_ = unicode
import types, new
from cStringIO import StringIO
from warnings import warn
......@@ -542,17 +543,6 @@ class Adapter(AppObject):
__registry__ = 'adapters'
class EntityAdapter(Adapter):
"""base class for entity adapters (eg adapt an entity to an interface)"""
def __init__(self, _cw, **kwargs):
try:
self.entity = kwargs.pop('entity')
except KeyError:
self.entity = kwargs['rset'].get_entity(kwargs.get('row') or 0,
kwargs.get('col') or 0)
Adapter.__init__(self, _cw, **kwargs)
def implements_adapter_compat(iface):
def _pre39_compat(func):
def decorated(self, *args, **kwargs):
......@@ -567,5 +557,35 @@ def implements_adapter_compat(iface):
return member(*args, **kwargs)
return member
return func(self, *args, **kwargs)
decorated.decorated = func
return decorated
return _pre39_compat
def unwrap_adapter_compat(cls):
parent = cls.__bases__[0]
for member_name in dir(parent):
member = getattr(parent, member_name)
if isinstance(member, types.MethodType) and hasattr(member.im_func, 'decorated') and not member_name in cls.__dict__:
method = new.instancemethod(member.im_func.decorated, None, cls)
setattr(cls, member_name, method)
class auto_unwrap_bw_compat(type):
def __new__(mcs, name, bases, classdict):
cls = type.__new__(mcs, name, bases, classdict)
if not classdict.get('__needs_bw_compat__'):
unwrap_adapter_compat(cls)
return cls
class EntityAdapter(Adapter):
"""base class for entity adapters (eg adapt an entity to an interface)"""
__metaclass__ = auto_unwrap_bw_compat
def __init__(self, _cw, **kwargs):
try:
self.entity = kwargs.pop('entity')
except KeyError:
self.entity = kwargs['rset'].get_entity(kwargs.get('row') or 0,
kwargs.get('col') or 0)
Adapter.__init__(self, _cw, **kwargs)
......@@ -31,6 +31,7 @@ from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat
class ICalendarableAdapter(EntityAdapter):
__needs_bw_compat__ = True
__regid__ = 'ICalendarable'
__select__ = implements(ICalendarable, warn=False) # XXX for bw compat, should be abstract
......
......@@ -34,6 +34,7 @@ from cubicweb.web.views import basecontrollers, autoform
class IEditControlAdapter(EntityAdapter):
__needs_bw_compat__ = True
__regid__ = 'IEditControl'
__select__ = is_instance('Any')
......
......@@ -41,6 +41,7 @@ from cubicweb.web.views import basetemplates
class IEmbedableAdapter(EntityAdapter):
"""interface for embedable entities"""
__needs_bw_compat__ = True
__regid__ = 'IEmbedable'
__select__ = implements(IEmbedable, warn=False) # XXX for bw compat, should be abstract
......
......@@ -26,6 +26,7 @@ from cubicweb.utils import json_dumps
class IGeocodableAdapter(EntityAdapter):
"""interface required by geocoding views such as gmap-view"""
__needs_bw_compat__ = True
__regid__ = 'IGeocodable'
__select__ = implements(IGeocodable, warn=False) # XXX for bw compat, should be abstract
......
......@@ -32,6 +32,7 @@ from cubicweb.interfaces import ISiocItem, ISiocContainer
class ISIOCItemAdapter(EntityAdapter):
"""interface for entities which may be represented as an ISIOC items"""
__needs_bw_compat__ = True
__regid__ = 'ISIOCItem'
__select__ = implements(ISiocItem, warn=False) # XXX for bw compat, should be abstract
......@@ -63,6 +64,7 @@ class ISIOCItemAdapter(EntityAdapter):
class ISIOCContainerAdapter(EntityAdapter):
"""interface for entities which may be represented as an ISIOC container"""
__needs_bw_compat__ = True
__regid__ = 'ISIOCContainer'
__select__ = implements(ISiocContainer, warn=False) # XXX for bw compat, should be abstract
......
......@@ -187,6 +187,7 @@ class IPrevNextAdapter(EntityAdapter):
"""interface for entities which can be linked to a previous and/or next
entity
"""
__needs_bw_compat__ = True
__regid__ = 'IPrevNext'
__select__ = implements(IPrevNext, warn=False) # XXX for bw compat, else should be abstract
......
......@@ -32,6 +32,7 @@ from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat
class ICalendarViewsAdapter(EntityAdapter):
"""calendar views interface"""
__needs_bw_compat__ = True
__regid__ = 'ICalendarViews'
__select__ = implements(ICalendarViews, warn=False) # XXX for bw compat, should be abstract
......
......@@ -122,6 +122,7 @@ class XMLRsetView(AnyRsetView):
# RSS stuff ###################################################################
class IFeedAdapter(EntityAdapter):
__needs_bw_compat__ = True
__regid__ = 'IFeed'
__select__ = is_instance('Any')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment