| 21 | |
| 22 | |
| 23 | class ForkManage: |
| 24 | def __init__(self, base_url: str, selector_list: List[str]): |
| 25 | self.base_url = base_url |
| 26 | self.selector_list = selector_list |
| 27 | |
| 28 | def fork(self, level: int, exclude_link_url: Set[str], fork_handler): |
| 29 | self.fork_child(ChildLink(self.base_url, None), self.selector_list, level, exclude_link_url, fork_handler) |
| 30 | |
| 31 | @staticmethod |
| 32 | def fork_child(child_link: ChildLink, selector_list: List[str], level: int, exclude_link_url: Set[str], |
| 33 | fork_handler): |
| 34 | if level < 0: |
| 35 | return |
| 36 | else: |
| 37 | child_link.url = remove_fragment(child_link.url) |
| 38 | child_url = child_link.url[:-1] if child_link.url.endswith('/') else child_link.url |
| 39 | if not exclude_link_url.__contains__(child_url): |
| 40 | exclude_link_url.add(child_url) |
| 41 | response = Fork(child_link.url, selector_list).fork() |
| 42 | fork_handler(child_link, response) |
| 43 | for child_link in response.child_link_list: |
| 44 | child_url = child_link.url[:-1] if child_link.url.endswith('/') else child_link.url |
| 45 | if not exclude_link_url.__contains__(child_url): |
| 46 | ForkManage.fork_child(child_link, selector_list, level - 1, exclude_link_url, fork_handler) |
| 47 | |
| 48 | |
| 49 | def remove_fragment(url: str) -> str: |
no outgoing calls
no test coverage detected