Skip to content

Commit

Permalink
Merge pull request #33 from scrapy/add-more-docstrings
Browse files Browse the repository at this point in the history
Add docstrings to re_first and extract_first (closes #30)
  • Loading branch information
dangra committed Mar 22, 2016
2 parents aeeb9ac + 6d9e675 commit 04e6e14
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion parsel/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ def css(self, xpath):

def re(self, regex):
"""
Call the ``.re()`` method for each element is this list and return
Call the ``.re()`` method for each element in this list and return
their results flattened, as a list of unicode strings.
"""
return flatten([x.re(regex) for x in self])

def re_first(self, regex):
"""
Call the ``.re()`` method for the first element in this list and
return the result in an unicode string.
"""
for el in iflatten(x.re(regex) for x in self):
return el

Expand All @@ -93,6 +97,10 @@ def extract(self):
return [x.extract() for x in self]

def extract_first(self, default=None):
"""
Return the result of ``.extract()`` for the first element in this list.
If the list is empty, return the default value.
"""
for x in self:
return x.extract()
else:
Expand Down

0 comments on commit 04e6e14

Please sign in to comment.