Scrapy, a fast high-level web crawling & scraping framework for Python.
Added method for inserting adaptors into a pipeline
elpolilla82cf911192c5
diff --git a/scrapy/trunk/scrapy/item/models.py b/scrapy/trunk/scrapy/item/models.pyindex 004844f26..b36542941 100644--- a/scrapy/trunk/scrapy/item/models.py+++ b/scrapy/trunk/scrapy/item/models.py@@ -18,10 +18,21 @@ class ScrapedItem(object):return selfdef set_attrib_adaptors(self, attrib, pipe):+ """ Set the adaptors (from a list or tuple) to be used for a specific attribute. """+ self._adaptors_dict[attrib] = AdaptorPipe(pipe) if hasattr(pipe, '__iter__') else None++ def add_adaptor(self, attrib, adaptor, position=None):"""- Set the adaptors (from a list or tuple) to be used for a specific attribute.+ Add an adaptor for the specified attribute at the given position.+ If position = None, then the adaptor is appended at the end of the pipeline."""- self._adaptors_dict[attrib] = AdaptorPipe(pipe) if hasattr(pipe, '__iter__') else None+ if callable(adaptor):+ pipe = self._adaptors_dict.get(attrib, [])+ if position is None:+ pipe = pipe + [adaptor]+ else:+ pipe.insert(position, adaptor)+ self.set_attrib_adaptors(attrib, pipe)def attribute(self, attrname, value, **kwargs):pipe = self._adaptors_dict.get(attrname)