Commit 938e0d45 authored by Jerome Berthier's avatar Jerome Berthier Committed by ntome

weboob.browser.browser: allow multiple inheritance with AbstractBrowser

When instanciating an AbstractBrowser the 'AbstractBrowser' class was
actually replaced with the class defined in the PARENT attribute.

This behavior did not allow multiple ineritance as the whole
class __basess__ was replaced with the PARENT.

Moreover when you try to inherit an AbstractBrowser from another
AbstractBrowser, only the first AbstractBrowser class was replaced
with the PARENT attribute.

This patch fixes these behaviors by walking over the full parents tree
to replace AbstractBrowser with the current class defined in the
PARENT attributes.
parent 7ae2d402
......@@ -943,7 +943,7 @@ class AbstractBrowser(Browser):
PARENT is a mandatory attribute, it's the name of the module providing the parent Browser
PARENT_ATTR is an optionnal attribute used when the parent module does not have only one
PARENT_ATTR is an optional attribute used when the parent module does not have only one
browser defined as BROWSER class attribute: you can customized the path of the object to load.
Note that you must pass a valid weboob instance as first argument of the constructor.
......@@ -951,9 +951,8 @@ class AbstractBrowser(Browser):
PARENT = None
PARENT_ATTR = None
def __new__(cls, *args, **kwargs):
weboob = kwargs['weboob']
@classmethod
def _resolve_abstract(cls, weboob):
if cls.PARENT is None:
raise AbstractBrowserMissingParentError("PARENT is not defined for browser %s" % cls)
......@@ -970,7 +969,15 @@ class AbstractBrowser(Browser):
if parent is None:
raise AbstractBrowserMissingParentError("Failed to load parent class")
# Parent may be an AbstractBrowser as well
if hasattr(parent, '_resolve_abstract'):
parent._resolve_abstract(weboob)
cls.__bases__ = (parent,)
def __new__(cls, *args, **kwargs):
weboob = kwargs['weboob']
cls._resolve_abstract(weboob)
return object.__new__(cls)
......
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