Coverage for src/rsnapshot_docker_compose_backup/utils/regex.py: 53%

15 statements  

« prev     ^ index     » next       coverage.py v7.5.4, created at 2024-07-07 01:03 +0200

1from re import Match, Pattern 

2from typing import Optional 

3 

4 

5class CaseInsensitiveMatch: 

6 def __init__(self, match: Match[str]): 

7 self.match = match 

8 

9 def group(self, name: str) -> str: 

10 return self.match.group(name).lower() 

11 

12 

13class CaseInsensitiveRe: 

14 def __init__(self, regex: Pattern[str]): 

15 self.regex = regex 

16 

17 def match(self, text: str) -> Optional[CaseInsensitiveMatch]: 

18 m: Optional[Match[str]] = self.regex.match(text) 

19 if m: 

20 return CaseInsensitiveMatch(m) 

21 return None