Skip to content

Commit

Permalink
just a demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Digenis committed Apr 13, 2014
1 parent ade7662 commit 1f088d4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scrapy/contrib/loader/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,32 @@ def __call__(self, value, loader_context=None):
return value


class Filter(object):

def __init__(self, function=lambda v: v is not None and v != ''):
self.function = function

def __call__(self, values):
return tuple(filter(self.function, values))


class Slice(object):

def __init__(self, begin=None, end=None):
self.begin, self.end = begin, end

def __call__(self, values):
return values[self.begin:self.end]


class TakeFirst(object):

def __init__(self, function=lambda v: v is not None and v != ''):
self.function = bool if function is None else function

def __call__(self, values):
for value in values:
if value is not None and value != '':
if self.function(value):
return value


Expand Down

0 comments on commit 1f088d4

Please sign in to comment.