mirror of https://github.com/scrapy/scrapy.git
Removed non-generic implementation of _add_single_attributes and modified test
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40791
This commit is contained in:
parent
bc4fcbeab7
commit
3ca2187e3b
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in New Issue