Esempio n. 1
0
    def test_map_compose_filter(self):
        def filter_world(x):
            return None if x == 'world' else x

        proc = MapCompose(filter_world, str.upper)
        self.assertEqual(proc(['hello', 'world', 'this', 'is', 'scrapy']),
                         ['HELLO', 'THIS', 'IS', 'SCRAPY'])
Esempio n. 2
0
 def test_mapcompose(self):
     filter_world = lambda x: None if x == 'world' else x
     proc = MapCompose(filter_world, six.text_type.upper)
     self.assertEqual(proc([u'hello', u'world', u'this', u'is', u'scrapy']),
                      [u'HELLO', u'THIS', u'IS', u'SCRAPY'])
Esempio n. 3
0
class DefaultedItemLoader(NameItemLoader):
    default_input_processor = MapCompose(lambda v: v[:-1])
Esempio n. 4
0
class TstItemLoader(NameItemLoader):
    name_in = MapCompose(lambda v: v.title())
Esempio n. 5
0
 class ChildItemLoader(TstItemLoader):
     url_in = MapCompose(processor)
Esempio n. 6
0
 class ChildItemLoader(TstItemLoader):
     url_in = MapCompose(processor_with_args, key=u'val')
Esempio n. 7
0
 class TstItemLoader(ItemLoader):
     default_item_class = TstItem
     name_out = MapCompose(float)
Esempio n. 8
0
 class ChildDefaultedItemLoader(DefaultedItemLoader):
     name_in = MapCompose(DefaultedItemLoader.default_input_processor,
                          six.text_type.swapcase)
Esempio n. 9
0
 class ChildItemLoader(TstItemLoader):
     name_in = MapCompose(TstItemLoader.name_in, six.text_type.swapcase)
Esempio n. 10
0
 class IdentityDefaultedItemLoader(DefaultedItemLoader):
     name_in = MapCompose()
Esempio n. 11
0
 class ChildChildItemLoader(ChildItemLoader):
     url_in = MapCompose(lambda v: v.upper())
     summary_in = MapCompose(lambda v: v)
Esempio n. 12
0
 class ChildItemLoader(TstItemLoader):
     url_in = MapCompose(lambda v: v.lower())
Esempio n. 13
0
        old_locale = localelib.getlocale(localelib.LC_TIME)
        localelib.setlocale(localelib.LC_TIME, locale)

    time_s = time.strptime(value, format)
    dt = datetime.datetime(*time_s[0:5])
    # 1900 is the default year from strptime, means no year parsed
    if dt.year == 1900:
        dt = dt.replace(year=datetime.datetime.utcnow().year)

    if locale:
        localelib.setlocale(localelib.LC_TIME, old_locale)

    return dt


def to_date(value, format, locale=None):
    return to_datetime(value, format, locale).date()


def to_time(value, format):
    time_s = time.strptime(value, format)
    return datetime.time(time_s[3], time_s[4])


# defaults

default_input_processor = MapCompose(replace_br, remove_tags, unquote_markup,
                                     replace_escape, strip, clean_spaces)

default_output_processor = TakeFirst()