Coverage for presidio_analyzer / predefined_recognizers / country_specific / italy / it_passport_recognizer.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-29 09:03 +0000

1from typing import List, Optional 

2 

3from presidio_analyzer import Pattern, PatternRecognizer 

4 

5 

6class ItPassportRecognizer(PatternRecognizer): 

7 """ 

8 Recognizes IT Passport number using case-insensitive regex. 

9 

10 :param patterns: List of patterns to be used by this recognizer 

11 :param context: List of context words to increase confidence in detection 

12 :param supported_language: Language this recognizer supports 

13 :param supported_entity: The entity this recognizer can detect 

14 """ 

15 

16 PATTERNS = [ 

17 Pattern( 

18 "Passport (very weak)", 

19 r"(?i)\b[A-Z]{2}\d{7}\b", 

20 0.01, 

21 ), 

22 ] 

23 

24 CONTEXT = [ 

25 "passaporto", 

26 "elettronico", 

27 "italiano", 

28 "viaggio", 

29 "viaggiare", 

30 "estero", 

31 "documento", 

32 "dogana", 

33 ] 

34 

35 def __init__( 

36 self, 

37 patterns: Optional[List[Pattern]] = None, 

38 context: Optional[List[str]] = None, 

39 supported_language: str = "it", 

40 supported_entity: str = "IT_PASSPORT", 

41 name: Optional[str] = None, 

42 ): 

43 patterns = patterns if patterns else self.PATTERNS 

44 context = context if context else self.CONTEXT 

45 super().__init__( 

46 supported_entity=supported_entity, 

47 patterns=patterns, 

48 context=context, 

49 supported_language=supported_language, 

50 name=name, 

51 )