Coverage for src/ensae_teaching_cs/homeblog/clean_python_script_before_exporting_outside.py: 25%

16 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-01-27 05:44 +0100

1""" 

2@file 

3@brief Too old to remember what it is needed 

4""" 

5 

6import re 

7 

8 

9def cleanFileFromtohtmlreplace(content): 

10 

11 if "#" + "## tohtmlreplace BEGIN ###" in content: 

12 exps = "(#" + "## tohtmlreplace BEGIN ###((.|\n)*?)" 

13 exps += "#" + "## tohtmlreplace ELSE ###((.|\n)*?)" 

14 exps += "#" + "## tohtmlreplace END ###" 

15 exps += ")" 

16 exp = re.compile(exps) 

17 res = exp.findall(content) 

18 if len(res) == 0: 

19 raise ValueError("unable to understand the format\n" + exps) 

20 

21 for rs in res: 

22 torep = rs[0] 

23 byrep = rs[1] 

24 content = content.replace(torep, byrep) 

25 

26 return content