Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Removed non-generic implementation of _add_single_attributes and modified test

elpolilla3ca2187e3b01
diff --git a/scrapy/trunk/scrapy/contrib/item/models.py b/scrapy/trunk/scrapy/contrib/item/models.py
index a5be1a1c8..521504071 100644
--- a/scrapy/trunk/scrapy/contrib/item/models.py
+++ b/scrapy/trunk/scrapy/contrib/item/models.py
@@ -111,13 +111,7 @@ class RobustScrapedItem(ScrapedItem):
return "%s: GUID=%s, url=%s" % ( self.__class__.__name__ , self.guid, self.url )
def _add_single_attributes(self, attrname, attrtype, attributes):
- if len(attributes) == 1:
- return attributes[0]
-
- if attrtype is basestring:
- return ''.join(attributes)
- else:
- raise NotImplementedError('You must override _add_single_attributes method in order to join %s values into a single value.' % attrtype.__name__)
+ raise NotImplementedError('You must override _add_single_attributes method in order to join %s values into a single value.' % attrtype.__name__)
def attribute(self, attrname, *values, **kwargs):
"""
@@ -171,7 +165,7 @@ class RobustScrapedItem(ScrapedItem):
new_values.insert(0, old_value)
if not multivalued:
- if add and len(new_values) >= 1:
+ if add and len(new_values) > 1:
new_values = self._add_single_attributes(attrname, attrtype, new_values)
else:
new_values = new_values[0] if new_values else None
diff --git a/scrapy/trunk/scrapy/tests/test_robustscrapeditem.py b/scrapy/trunk/scrapy/tests/test_robustscrapeditem.py
index 184e3323b..8f770cc1d 100644
--- a/scrapy/trunk/scrapy/tests/test_robustscrapeditem.py
+++ b/scrapy/trunk/scrapy/tests/test_robustscrapeditem.py
@@ -46,9 +46,7 @@ class RobustScrapedItemTestCase(unittest.TestCase):
def test_attribute_add(self):
self.item.attribute('name', 'John')
-
- self.item.attribute('name', 'Doe', add=True)
- self.assertEqual(self.item.name, 'JohnDoe')
+ self.assertRaises(NotImplementedError, self.item.attribute, 'name', 'Doe', add=True)
self.item.attribute('children', *['Ken', 'Tom'])
self.item.attribute('children', 'Bobby')