Coverage for src/epublib/identifier.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-18 16:07 -0300

1import re 

2 

3start = ( 

4 r":A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D" 

5 r"\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF" 

6 r"\uF900-\uFDCF\uFDF0-\uFFFD\U00010000-\U000EFFFF" 

7) 

8name = start + r"-.0-9\u00B7\u0300-\u036F\u203F-\u2040" 

9 

10valid_id_pattern = re.compile(f"^[{start}][{name}]*$") 

11 

12 

13class EPUBId(str): 

14 """A unique identifier for a resource within an EPUB file. 

15 Use this class to reference epub resources throughout the library 

16 using it's manifest id rather than its complete filename. 

17 """ 

18 

19 def is_valid(self) -> bool: 

20 """Check if the identifier is valid according to the XML specification. 

21 

22 Returns: 

23 bool: True if the identifier is valid, False otherwise. 

24 """ 

25 return bool(valid_id_pattern.match(self))