diff --git a/docs/experimental/loaders.rst b/docs/experimental/loaders.rst index d96defb71..5b9885389 100644 --- a/docs/experimental/loaders.rst +++ b/docs/experimental/loaders.rst @@ -49,7 +49,7 @@ chapter `:: p.add_xpath('price', '//p[@id="price"]') p.add_xpath('stock', '//p[@id="stock"]') p.add_value('last_updated', 'today') # you can also use literal values - return p.populate_item() + return p.loader_item() By quickly looking at that code we can see the ``name`` field is being extracted from two different XPath locations in the page: @@ -65,7 +65,7 @@ Afterwards, similar calls are used for ``price`` and ``stock`` fields, and finally the ``last_update`` field is populated directly with a literal value (``today``) using a different method: :meth:`~ItemLoader.add_value`. -Finally, when all data is collected, the :meth:`ItemLoader.populate_item` +Finally, when all data is collected, the :meth:`ItemLoader.loader_item` method is called which actually populates and returns the item populated with the data previously extracted and collected with the :meth:`~XPathItemLoader.add_xpath` and :meth:`~ItemLoader.add_value` calls. @@ -80,7 +80,7 @@ An Item Loader contains one input processor and one output processor for each received (through the :meth:`~XPathItemLoader.add_xpath` or :meth:`~ItemLoader.add_value` methods) and the result of the input processor is collected and kept inside the ItemLoader. After collecting all data, the -:meth:`ItemLoader.populate_item` method is called to populate and get the +:meth:`ItemLoader.loader_item` method is called to populate and get the populated :class:`~scrapy.newitem.Item` object. That's when the output processor is called with the data previously collected (and processed using the input processor). The result of the output processor is the final value that gets assigned @@ -92,7 +92,7 @@ called for a particular field (the same applies for any other field):: p = XPathItemLoader(Product(), some_xpath_selector) p.add_xpath('name', xpath1) # (1) p.add_xpath('name', xpath2) # (2) - return p.populate_item() # (3) + return p.loader_item() # (3) So what happens is: @@ -263,10 +263,10 @@ ItemLoader objects Similar to :meth:`add_value` but replaces the collected data with the new value instead of adding it. - .. method:: populate_item() + .. method:: loader_item() Populate the item with the data collected so far, and return it. The - data collected is first passed through the :ref:`field output processors + data collected is first passed through the :ref:`output processors ` to get the final value to assign to each item field. diff --git a/scrapy/contrib/loader/__init__.py b/scrapy/contrib/loader/__init__.py index fc709c8ce..2a033dc7b 100644 --- a/scrapy/contrib/loader/__init__.py +++ b/scrapy/contrib/loader/__init__.py @@ -33,7 +33,7 @@ class ItemLoader(object): parsed_value = self._parse_input_value(field_name, value) self._values[field_name] = arg_to_iter(parsed_value) - def populate_item(self): + def load_item(self): item = self.item for field_name in self._values: item[field_name] = self.get_output_value(field_name) diff --git a/scrapy/tests/test_contrib_loader.py b/scrapy/tests/test_contrib_loader.py index 0f365b194..aa764775c 100644 --- a/scrapy/tests/test_contrib_loader.py +++ b/scrapy/tests/test_contrib_loader.py @@ -35,20 +35,20 @@ def processor_with_args(value, other=None, loader_context=None): class ItemLoaderTest(unittest.TestCase): - def test_populate_item_using_default_loader(self): + def test_load_item_using_default_loader(self): i = TestItem() i['summary'] = u'lala' ip = ItemLoader(item=i) ip.add_value('name', u'marta') - item = ip.populate_item() + item = ip.load_item() assert item is i self.assertEqual(item['summary'], u'lala') self.assertEqual(item['name'], [u'marta']) - def test_populate_item_using_custom_loader(self): + def test_load_item_using_custom_loader(self): ip = TestItemLoader() ip.add_value('name', u'marta') - item = ip.populate_item() + item = ip.load_item() self.assertEqual(item['name'], [u'Marta']) def test_add_value(self): @@ -84,7 +84,7 @@ class ItemLoaderTest(unittest.TestCase): ip = TestItemLoader() ip.add_value('name', u'marta') self.assertEqual(ip.get_output_value('name'), [u'Mart']) - item = ip.populate_item() + item = ip.load_item() self.assertEqual(item['name'], [u'Mart']) def test_default_input_processor(self): @@ -251,7 +251,7 @@ class ItemLoaderTest(unittest.TestCase): il = TestItemLoader() il.add_value('name', [u'marta', u'other']) self.assertEqual(il.get_output_value('name'), u'Mart') - item = il.populate_item() + item = il.load_item() self.assertEqual(item['name'], u'Mart')