diff --git a/scrapy/trunk/examples/contrib_exp/googledir/googledir/items.py b/scrapy/trunk/examples/contrib_exp/googledir/googledir/items.py index 857e05afc..38d3722fc 100644 --- a/scrapy/trunk/examples/contrib_exp/googledir/googledir/items.py +++ b/scrapy/trunk/examples/contrib_exp/googledir/googledir/items.py @@ -2,8 +2,8 @@ from scrapy.contrib_exp import newitem -from scrapy.contrib_exp.newitem import extractors -from scrapy.contrib_exp import adaptors +from scrapy.contrib_exp.newitem.extractors import ItemExtractor, adaptor +from scrapy.contrib_exp.adaptors import extract, strip class GoogledirItem(newitem.Item): @@ -12,9 +12,9 @@ class GoogledirItem(newitem.Item): description = newitem.StringField() -class GoogledirItemExtractor(extractors.ItemExtractor): +class GoogledirItemExtractor(ItemExtractor): item_class = GoogledirItem - name = extractors.ExtractorField([adaptors.extract, adaptors.strip]) - url = extractors.ExtractorField([adaptors.extract, adaptors.strip]) - description = extractors.ExtractorField([adaptors.extract, adaptors.strip]) + name = adaptor(extract, strip) + url = adaptor(extract, strip) + description = adaptor(extract, strip) diff --git a/scrapy/trunk/scrapy/contrib_exp/newitem/extractors.py b/scrapy/trunk/scrapy/contrib_exp/newitem/extractors.py index 5a9ff3bc9..0bafacef6 100644 --- a/scrapy/trunk/scrapy/contrib_exp/newitem/extractors.py +++ b/scrapy/trunk/scrapy/contrib_exp/newitem/extractors.py @@ -38,38 +38,6 @@ class ItemExtractor(object): return object.__getattribute__(self, name) -class ExtractorField(object): - def __init__(self, funcs): - if not hasattr(funcs, '__iter__'): - raise TypeError( - 'You must initialize ExtractorField with a list of callables') - - self._funcs = [] - - for func in funcs: - func_args = get_func_args(func) - takes_args = True if 'adaptor_args' in func_args else False - self._funcs.append((func, takes_args)) - - def __call__(self, value, adaptor_args=None): - values = [value] - - for func, takes_args in self._funcs: - next_round = [] - - for val in values: - val = func(val, adaptor_args) if takes_args else func(val) - - if isinstance(val, tuple): - next_round.extend(val) - elif val is not None: - next_round.append(val) - - values = next_round - - return list(values) - - def adaptor(*funcs, **adaptor_args): """A pipe adaptor implementing the tree adaption logic