From 76c84bda38915363c049fac718892d54ccf24d5e Mon Sep 17 00:00:00 2001 From: Ismael Carnales Date: Thu, 19 Feb 2009 12:39:58 +0000 Subject: [PATCH] always deiter on ItemField value assignation --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40877 --- scrapy/trunk/scrapy/contrib_exp/newitem/fields.py | 12 +++++++++--- scrapy/trunk/scrapy/contrib_exp/newitem/models.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) 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: