Merge lp://qastaging/~mszamot-gmail/beautifulsoup/beautifulsoup into lp://qastaging/beautifulsoup

Proposed by Marcin Szamotulski
Status: Needs review
Proposed branch: lp://qastaging/~mszamot-gmail/beautifulsoup/beautifulsoup
Merge into: lp://qastaging/beautifulsoup
Diff against target: 316 lines (+222/-23)
2 files modified
bs4/element.py (+78/-23)
bs4/tests/test_soup.py (+144/-0)
To merge this branch: bzr merge lp://qastaging/~mszamot-gmail/beautifulsoup/beautifulsoup
Reviewer Review Type Date Requested Status
Leonard Richardson Pending
Review via email: mp+166933@code.qastaging.launchpad.net

Commit message

Make Tag.descendants a proper generator. Make possible to resume iteration at a given node, which is important when one replaces nodes.

Description of the change

Make Tag.descendants a proper generator. With this patch one can send back where iteration should resume. This important if one replaces nodes with Tag.replace_with() method. See the doc string for an example.

To post a comment you must log in.
305. By Marcin Szamotulski

Make descendants a proper generator. This makes possible to resume iteration
at a given node, which is important when one replaces nodes.

Revision history for this message
Leonard Richardson (leonardr) wrote :

Quick questions:

1. Can you write some tests for this? Turning your docstring example into a test would be a good start.
2. Do you want to do this for the other generators as well?

306. By Marcin Szamotulski

Add a test for Tag.descendants generator

Revision history for this message
Marcin Szamotulski (mszamot-gmail) wrote :

On 11:08 Sat 01 Jun , Leonard Richardson wrote:
> Quick questions:
>
> 1. Can you write some tests for this? Turning your docstring example into a test would be a good start.
> 2. Do you want to do this for the other generators as well?
> --
> https://code.launchpad.net/~mszamot-gmail/beautifulsoup/beautifulsoup/+merge/166933
> You are the owner of lp:~mszamot-gmail/beautifulsoup/beautifulsoup.

Yes I will include some tests and I will add this for other generators
as well. Do you agree with returning iter([]) instead of None? It
makes a little bit easier to write an iteration loop, though iter([])
does not have send attribute. I don't know however how to build an
empty generator besides:

    def iterator_func()
 raise StopIteration
 yield None
    empty_gen = iterator_func() # is an empty generator with both next and send attribute

Best regards,
Marcin Szamotulski

307. By Marcin Szamotulski

Added proper generators and tests: Tag.next_elements, Tag.previous_elements,
Tag.next_siblings, Tag.previous_siblings, Tag.parents.

Unmerged revisions

307. By Marcin Szamotulski

Added proper generators and tests: Tag.next_elements, Tag.previous_elements,
Tag.next_siblings, Tag.previous_siblings, Tag.parents.

306. By Marcin Szamotulski

Add a test for Tag.descendants generator

305. By Marcin Szamotulski

Make descendants a proper generator. This makes possible to resume iteration
at a given node, which is important when one replaces nodes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to status/vote changes: