Coverage for liitos/patch.py: 100.00%

12 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-13 17:41:25 +00:00

1"""Apply all pairs in patches to incoming.""" 

2 

3from collections.abc import Iterable 

4 

5from liitos import log 

6 

7 

8def apply(patches: list[tuple[str, str]], incoming: Iterable[str]) -> list[str]: 

9 """Later alligator.""" 

10 outgoing = [line for line in incoming] 

11 

12 log.info(f'applying patches to {len(outgoing)} lines of text') 

13 for this, that in patches: 

14 log.info(f' - trying any ({this}) --> ({that}) ...') 

15 for n, text in enumerate(outgoing): 

16 if this in text: 

17 log.info(f' + found match ({text})') 

18 outgoing[n] = text.replace(this, that) 

19 

20 return outgoing