Yield groups of prepared candidate line lists where each list element is a tuple of (line number, line text) given an iterable of ``numbered_lines`` as tuples of (line number, line text) . A candidate line is a line of text that may contain copyright statements. A few lines b
(numbered_lines)
| 4330 | |
| 4331 | |
| 4332 | def collect_candidate_lines(numbered_lines): |
| 4333 | """ |
| 4334 | Yield groups of prepared candidate line lists where each list element is a tuple of |
| 4335 | (line number, line text) given an iterable of ``numbered_lines`` as tuples |
| 4336 | of (line number, line text) . |
| 4337 | |
| 4338 | A candidate line is a line of text that may contain copyright statements. |
| 4339 | A few lines before and after a candidate line are also included. |
| 4340 | """ |
| 4341 | candidates = deque() |
| 4342 | candidates_append = candidates.append |
| 4343 | candidates_clear = candidates.clear |
| 4344 | |
| 4345 | # used as a state and line counter |
| 4346 | in_copyright = 0 |
| 4347 | |
| 4348 | if TRACE_TOK: |
| 4349 | numbered_lines = list(numbered_lines) |
| 4350 | logger_debug(f'collect_candidate_lines: numbered_lines: {numbered_lines!r}') |
| 4351 | |
| 4352 | # the previous line (chars only) |
| 4353 | previous_chars = None |
| 4354 | for (ln, line) in numbered_lines: |
| 4355 | if TRACE: |
| 4356 | logger_debug(f'## collect_candidate_lines: evaluating line: {(ln, line)!r}') |
| 4357 | |
| 4358 | is_debian = 's>' in line |
| 4359 | prepared = prepare_text_line(line) |
| 4360 | if TRACE: |
| 4361 | logger_debug(f'## collect_candidate_lines: prepared: {prepared!r}, candidate: {is_candidate(prepared)}') |
| 4362 | |
| 4363 | chars_only = remove_non_chars('', line.lower()).strip() |
| 4364 | |
| 4365 | if is_end_of_statement(chars_only): |
| 4366 | candidates_append((ln, prepared,)) |
| 4367 | |
| 4368 | if TRACE: |
| 4369 | logger_debug(f' collect_candidate_lines: is EOS: yielding candidates\n {list(candidates)!r}\n') |
| 4370 | |
| 4371 | yield list(candidates) |
| 4372 | candidates_clear() |
| 4373 | in_copyright = 0 |
| 4374 | previous_chars = None |
| 4375 | |
| 4376 | # <s> and </s> are legacy debian-style copyright name tags in copyright files |
| 4377 | # http are for copyrights listing many URLs |
| 4378 | elif is_candidate(prepared) or 'http' in chars_only or is_debian: |
| 4379 | # the state is now "in copyright" |
| 4380 | in_copyright = 2 |
| 4381 | candidates_append((ln, prepared,)) |
| 4382 | previous_chars = chars_only |
| 4383 | if TRACE: |
| 4384 | logger_debug(' collect_candidate_lines: line is candidate') |
| 4385 | |
| 4386 | elif in_copyright > 0: |
| 4387 | # these are a sign that the copyrights continue after |
| 4388 | # a possibly empty line |
| 4389 | # see https://github.com/nexB/scancode-toolkit/issues/1565 |
no test coverage detected