mirror of
https://github.com/scrapy/scrapy.git
synced 2025-02-27 15:04:21 +00:00
Added method for inserting adaptors into a pipeline
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40405
This commit is contained in:
parent
0f9eba8a97
commit
82cf911192
@ -18,11 +18,22 @@ class ScrapedItem(object):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def set_attrib_adaptors(self, attrib, pipe):
|
def set_attrib_adaptors(self, attrib, pipe):
|
||||||
"""
|
""" Set the adaptors (from a list or tuple) to be used for a specific attribute. """
|
||||||
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
|
self._adaptors_dict[attrib] = AdaptorPipe(pipe) if hasattr(pipe, '__iter__') else None
|
||||||
|
|
||||||
|
def add_adaptor(self, attrib, adaptor, position=None):
|
||||||
|
"""
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
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):
|
def attribute(self, attrname, value, **kwargs):
|
||||||
pipe = self._adaptors_dict.get(attrname)
|
pipe = self._adaptors_dict.get(attrname)
|
||||||
if pipe:
|
if pipe:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user