Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Legifrance (2020) layout #11

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Support python 2.7 as the rest of the project does
Might not be worth the effort
  • Loading branch information
Cimbali committed Apr 29, 2021
commit a932cb4ed7d3653227e20fd1e4f4efc59ef95809
8 changes: 6 additions & 2 deletions legipy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,21 @@ def parse_roman(string):
return total


def find_all_non_nested(parent, *args, bfs=False, **kwargs):
def find_all_non_nested(parent, *args, **kwargs):
""" find_all for non-nested elements

I.e. the same semantics as find_all(..., recursive=True),
except we don’t search children of matched nodes
"""
# Indulge python 2 ?
bfs = kwargs.pop('bfs', False)
kwargs['recursive'] = False

search = [parent]
found = []
while search:
node = search.pop(0 if bfs else -1)
found_at_node = node.find_all(*args, **kwargs, recursive=False)
found_at_node = node.find_all(*args, **kwargs)
found += found_at_node
search.extend(child for child in node.children if (
isinstance(child, Tag) and child not in found_at_node
Expand Down