diff options
author | Leonard Richardson <leonardr@segfault.org> | 2013-08-12 12:02:18 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2013-08-12 12:02:18 -0400 |
commit | c22a10a31aa0bc6671ce22509dade90496736b32 (patch) | |
tree | 8916b29ca7e2bcc6fd7315068444cb88147db7be /bs4/element.py | |
parent | b7fae1bd115492eb489359715ed74a742e664f46 (diff) |
All find_all calls should now return a ResultSet object. Patch by
Aaron DeVore. [bug=1194034]
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/bs4/element.py b/bs4/element.py index f248895..2484853 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -477,20 +477,20 @@ class PageElement(object): if isinstance(name, SoupStrainer): strainer = name - elif text is None and not limit and not attrs and not kwargs: + else: + strainer = SoupStrainer(name, attrs, text, **kwargs) + + if text is None and not limit and not attrs and not kwargs: # Optimization to find all tags. if name is True or name is None: - return [element for element in generator - if isinstance(element, Tag)] + result = (element for element in generator + if isinstance(element, Tag)) + ResultSet(strainer, result) # Optimization to find all tags with a given name. elif isinstance(name, basestring): - return [element for element in generator - if isinstance(element, Tag) and element.name == name] - else: - strainer = SoupStrainer(name, attrs, text, **kwargs) - else: - # Build a SoupStrainer - strainer = SoupStrainer(name, attrs, text, **kwargs) + result = (element for element in generator + if isinstance(element, Tag) + and element.name == name) results = ResultSet(strainer) while True: try: @@ -1602,6 +1602,6 @@ class SoupStrainer(object): class ResultSet(list): """A ResultSet is just a list that keeps track of the SoupStrainer that created it.""" - def __init__(self, source): - list.__init__([]) + def __init__(self, source, result=()): + super(list, self).__init__(result) self.source = source |