mirror of https://github.com/scrapy/scrapy.git
removed deprecated ScrapedItem (previously kept for backwards compatibility)
This commit is contained in:
parent
791f4932dd
commit
4a2a20489d
|
|
@ -7,7 +7,7 @@ BOT_VERSION = '1.0'
|
|||
|
||||
SPIDER_MODULES = ['googledir.spiders']
|
||||
NEWSPIDER_MODULE = 'googledir.spiders'
|
||||
DEFAULT_ITEM_CLASS = 'scrapy.item.ScrapedItem'
|
||||
DEFAULT_ITEM_CLASS = 'scrapy.item.Item'
|
||||
USER_AGENT = '%s/%s' % (BOT_NAME, BOT_VERSION)
|
||||
|
||||
ITEM_PIPELINES = ['googledir.pipelines.FilterWordsPipeline']
|
||||
|
|
|
|||
|
|
@ -83,29 +83,3 @@ class Item(DictItem):
|
|||
|
||||
__metaclass__ = ItemMeta
|
||||
|
||||
|
||||
class ScrapedItem(BaseItem):
|
||||
|
||||
def __init__(self, data=None):
|
||||
"""
|
||||
A ScrapedItem can be initialised with a dictionary that will be
|
||||
squirted directly into the object.
|
||||
"""
|
||||
import warnings
|
||||
warnings.warn("scrapy.item.ScrapedItem is deprecated, use scrapy.item.Item instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
if isinstance(data, dict):
|
||||
for attr, value in data.iteritems():
|
||||
setattr(self, attr, value)
|
||||
elif data is not None:
|
||||
raise TypeError("Initialize with dict, not %s" % data.__class__.__name__)
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
Generate the following format so that items can be deserialized
|
||||
easily: ClassName({'attrib': value, ...})
|
||||
"""
|
||||
reprdict = dict(items for items in self.__dict__.iteritems() \
|
||||
if not items[0].startswith('_'))
|
||||
return "%s(%s)" % (self.__class__.__name__, repr(reprdict))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import unittest
|
||||
|
||||
from scrapy.item import Item, Field, ScrapedItem
|
||||
from scrapy.item import Item, Field
|
||||
|
||||
|
||||
class ItemTest(unittest.TestCase):
|
||||
|
|
@ -127,23 +127,5 @@ class ItemTest(unittest.TestCase):
|
|||
self.assertEqual(dict(i), {'name': u'John'})
|
||||
|
||||
|
||||
# NOTE: ScrapedItem is deprecated and will be removed in the next stable
|
||||
# release, and so will these tests.
|
||||
|
||||
class ScrapedItemTestCase(unittest.TestCase):
|
||||
|
||||
def test_item(self):
|
||||
|
||||
class MyItem(ScrapedItem):
|
||||
pass
|
||||
|
||||
item = MyItem()
|
||||
self.assertEqual(repr(item), 'MyItem({})')
|
||||
|
||||
item = ScrapedItem({'key': 'value'})
|
||||
self.assertEqual(item.key, 'value')
|
||||
|
||||
self.assertRaises(TypeError, ScrapedItem, 10)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in New Issue