diff --git a/scrapy/trunk/scrapy/contrib_exp/newitem/fields.py b/scrapy/trunk/scrapy/contrib_exp/newitem/fields.py index 2352e115f..edf56ad5f 100644 --- a/scrapy/trunk/scrapy/contrib_exp/newitem/fields.py +++ b/scrapy/trunk/scrapy/contrib_exp/newitem/fields.py @@ -12,6 +12,12 @@ class ItemField(object): self.required = required self.default = default + def assign(self, value): + if hasattr(value, '__iter__'): + return self.to_python(self.deiter(value)) + else: + return self.to_python(value) + def to_python(self, value): """ Converts the input value into the expected Python data type. @@ -19,9 +25,9 @@ class ItemField(object): """ return value - def from_list(self, list): - "Converts the input list into the expected Python data type." - return self.to_python(list.join('')) + def deiter(self, value): + "Converts the input iterable into a single value." + return ' '.join(value) def default_value(self): "Returns the default value for this field" diff --git a/scrapy/trunk/scrapy/contrib_exp/newitem/models.py b/scrapy/trunk/scrapy/contrib_exp/newitem/models.py index 9f75846d9..21e2e1dda 100644 --- a/scrapy/trunk/scrapy/contrib_exp/newitem/models.py +++ b/scrapy/trunk/scrapy/contrib_exp/newitem/models.py @@ -17,7 +17,7 @@ class Item(object): def __setattr__(self, name, value): if not name.startswith('_'): if name in self._fields.keys(): - self._values[name] = self._fields[name].to_python(value) + self._values[name] = self._fields[name].assign(value) else: raise AttributeError(name) else: