mirror of https://github.com/scrapy/scrapy.git
Added class constructors scrapy.contrib.ibl FieldDescriptor and ItemDescriptor
This commit is contained in:
parent
23b13f0cc8
commit
dbc0ba7236
|
|
@ -17,6 +17,12 @@ class FieldDescriptor(object):
|
|||
self.required = required
|
||||
self.allow_markup = allow_markup
|
||||
|
||||
@classmethod
|
||||
def from_field(cls, name, field):
|
||||
return cls(name, field.get('description'), \
|
||||
field.get('ibl_extractor', text), field.get('required', False), \
|
||||
field.get('allow_markup', False))
|
||||
|
||||
def __str__(self):
|
||||
return "FieldDescriptor(%s)" % self.name
|
||||
|
||||
|
|
@ -33,6 +39,11 @@ class ItemDescriptor(object):
|
|||
self._required_attributes = [d.name for d in attribute_descriptors \
|
||||
if d.required]
|
||||
|
||||
@classmethod
|
||||
def from_item(cls, name, description, item):
|
||||
a = [FieldDescriptor.from_field(n, f) for n, f in item.fields.items()]
|
||||
return cls(name, description, a)
|
||||
|
||||
def validated(self, data):
|
||||
"""Only return the items in the data that are valid"""
|
||||
return [d for d in data if self._item_validates(d)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue