Commit dbd87d22 authored by Romain Bignon's avatar Romain Bignon

move handle_loaders into AbstractElement

parent 61aa684c
......@@ -54,6 +54,8 @@ class AbstractElement(object):
else:
self.env = deepcopy(page.params)
self.loaders = {}
def use_selector(self, func):
if isinstance(func, _Filter):
value = func(self)
......@@ -73,6 +75,17 @@ class AbstractElement(object):
def xpath(self, *args, **kwargs):
return self.el.xpath(*args, **kwargs)
def handle_loaders(self):
for attrname in dir(self):
m = re.match('load_(.*)', attrname)
if not m:
continue
name = m.group(1)
if name in self.loaders:
continue
loader = getattr(self, attrname)
self.loaders[name] = self.use_selector(loader)
class ListElement(AbstractElement):
item_xpath = None
......@@ -199,7 +212,6 @@ class ItemElement(AbstractElement):
super(ItemElement, self).__init__(*args, **kwargs)
self.logger = getLogger(self.__class__.__name__.lower())
self.obj = None
self.loaders = {}
def build_object(self):
if self.klass is None:
......@@ -232,17 +244,6 @@ class ItemElement(AbstractElement):
yield self.obj
def handle_loaders(self):
for attrname in dir(self):
m = re.match('load_(.*)', attrname)
if not m:
continue
name = m.group(1)
if name in self.loaders:
continue
loader = getattr(self, attrname)
self.loaders[name] = self.use_selector(loader)
def handle_attr(self, key, func):
try:
value = self.use_selector(func)
......
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